如何在python中重置输入流?

如何在python中重置输入流?,python,input,command-prompt,Python,Input,Command Prompt,我正在Python2.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 Valu

我正在Python2.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文件的情况下导入新数据,因为我的目标是按照DJV的建议,使用py2exe将*.py转换为*.exe中的*.py,我认为这很简单,只要将脚本包装在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):")

您的问题是什么?将所有内容放入
while
循环中,仅在用户输入时退出(一个附加输入,如
原始输入(“想要退出?”)
?@Robᵩ : 如何在python中重置输入流?