-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 に答える