-1

我正在 Python 2.7 中编写提示参数,以便使用命令行界面导入我的数据文件。

REFERENCE = raw_input("Reference (*.shp):")
SEGMENTED = raw_input("Segmented (*.shp):")
METHOD = raw_input("Method (ke, pu, clinton):")
if METHOD != "ke" and METHOD != "pu" and METHOD != "clinton":
    raise ValueError("%s is not a valid method" % METHOD)
if METHOD == "ke" or METHOD == "clinton":
    THRESHOLD = input("Threshold (0.0 - 1.0):")
    if not check_threshold(THRESHOLD):
        raise AccuracyException("Threshold of %s is not valid" % THRESHOLD)
else:
    THRESHOLD = None
SEP = raw_input("Sep:")
if SEP != "space" and SEP != "tab" and SEP != "comma" and SEP != "colon" and SEP != "semicolon" and SEP != "hyphen" and SEP != "dot":
    raise ValueError("%s is not valid" % SEP)
HEADER = raw_input("Header (True/False):")
if HEADER.strip() != "True" and HEADER.strip() != "False":
    raise ValueError("%s is not valid" % HEADER)
# output 
OUTPUT = raw_input("Output (*.txt):")

加载后我希望从头开始重置,以便在不重新加载 *.py 文件的情况下导入新数据,因为我的目标是使用 py2exe 将 *.py 转换为 *.exe

4

1 回答 1

1

正如 DJV 所建议的那样,我认为这就像将脚本包装在一个 while 循环中一样简单,以便在用户完成所有选项后在 while 块的顶部继续

while True:
  REFERENCE = raw_input("Reference (*.shp):")
  SEGMENTED = raw_input("Segmented (*.shp):")
  METHOD = raw_input("Method (ke, pu, clinton):")
  if METHOD != "ke" and METHOD != "pu" and METHOD != "clinton":
    raise ValueError("%s is not a valid method" % METHOD)
  if METHOD == "ke" or METHOD == "clinton":
    THRESHOLD = input("Threshold (0.0 - 1.0):")
    if not check_threshold(THRESHOLD):
        raise AccuracyException("Threshold of %s is not valid" % THRESHOLD)
  else:
    THRESHOLD = None
  SEP = raw_input("Sep:")
  if SEP != "space" and SEP != "tab" and SEP != "comma" and SEP != "colon" and SEP != "semicolon" and SEP != "hyphen" and SEP != "dot":
    raise ValueError("%s is not valid" % SEP)
  HEADER = raw_input("Header (True/False):")
  if HEADER.strip() != "True" and HEADER.strip() != "False":
    raise ValueError("%s is not valid" % HEADER)
  # output 
  OUTPUT = raw_input("Output (*.txt):")
于 2013-03-19T13:29:25.917 回答