【发布时间】:2019-06-05 19:00:30
【问题描述】:
我不断收到此错误:
TypeError: 'encoding' is an invalid keyword argument for this function.
当我运行我的代码时:
import re
f = open("/home/file/abc.sql", 'rt', encoding='latin-1')
source=f.read()
with open("/home/file/samp0l9.sql","w") as output:
output.write(re.sub(r'(TBLPROPERTIES \(.*?\))', r'\1;', f, flags=re.DOTALL))
关于为什么会这样的任何想法?文件里面只是一些文本。
【问题讨论】:
-
这段代码你运行的是什么版本的python?
-
我(几乎)确定您运行的是 Python 2 而不是 Python 3。
-
是的,你的权利。我什至没有注意到。
-
这就解释了问题所在。内置的
open函数在 Python 3 中仅接受encoding。
标签: python python-2.x