Python:SyntaxError:non关键字after关键字arg

2024-05-23 16:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行以下代码时

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

是什么导致了这个错误?


Tags: retxtforos错误argfilescontent
1条回答
网友
1楼 · 发布于 2024-05-23 16:23:09

它只是说:

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

您指定了encoding作为关键字参数,但是"r"作为位置参数。关键字参数后不能有位置参数。也许你想做:

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

相关问题 更多 >