Python:SyntaxError:non关键字在关键字arg之后

Python:SyntaxError:non关键字在关键字arg之后,python,keyword,non-keyword,syntax-error,Python,Keyword,Non Keyword,Syntax Error,当我运行以下代码时 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 =

当我运行以下代码时

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

是什么导致了这个错误?

它只是说:

inputFile = open((x), encoding = "utf8", "r")
您已将
编码
指定为关键字参数,但将
“r”
指定为位置参数。关键字参数后不能有位置参数。也许你想做:

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

它只是说:

inputFile = open((x), encoding = "utf8", "r")
您已将
编码
指定为关键字参数,但将
“r”
指定为位置参数。关键字参数后不能有位置参数。也许你想做:

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

要真正弄清楚这一点,以下是我对初学者的回答: 您按错误的顺序输入了参数。
关键字参数具有以下样式:

nullable=True, unique=False
应该定义一个固定参数:True、False等。 非关键字参数不同:

name="Ricardo", fruit="chontaduro" 
此语法错误要求您首先将
name=“Ricardo”
及其所有类型(非关键字)放在
nullable=True的前面。


要真正弄清楚这一点,以下是我给初学者的答案: 您按错误的顺序输入了参数。

关键字参数具有以下样式:

nullable=True, unique=False
应该定义一个固定参数:True、False等。 非关键字参数不同:

name="Ricardo", fruit="chontaduro" 
此语法错误要求您首先将
name=“Ricardo”
及其所有类型(非关键字)放在
nullable=True的前面。


编码是指在
'r'之后
我想编码是指在
'r'之后
我想请参阅本教程了解更多信息:请参阅本教程了解更多信息: