43

次のコードを実行すると

def regEx1():
  os.chdir("C:/Users/Luke/Desktop/myFiles")
  files = os.listdir(".")
  os.mkdir("C:/Users/Luke/Desktop/FilesWithRegEx")
  regex_txt = input("Please enter the website your are looking for:")
  for x in (files):
    inputFile = open((x), encoding = "utf8", "r")
    content = inputFile.read()
    inputFile.close()
    regex = re.compile(regex_txt, re.IGNORECASE)
    if re.search(regex, content)is not None:
      shutil.copy(x, "C:/Users/Luke/Desktop/FilesWithRegEx")

for ループの後の最初の行を指す次のエラー メッセージが表示されます。

      ^

SyntaxError: non-keyword arg after keyword arg

このエラーの原因は何ですか?

4

2 に答える 2

79

それはまさにそれが言うことです:

inputFile = open((x), encoding = "utf8", "r")

encodingキーワード引数として指定しましたが"r"、位置引数として指定しました。キーワード引数の後に位置引数を指定することはできません。おそらくあなたはやりたいと思っていました:

inputFile = open((x), "r", encoding = "utf8")
于 2013-01-09T22:36:57.070 に答える