我有一个代码用文本文件的扩展(例如没有)替换单词中的收缩(例如,没有)。
import os
import contractions
directory = 'C:\\Users\\User\\Desktop\\test1'
os.chdir('C:\\Users\\User\\Desktop\\test1')
for filename in os.listdir(directory):
if filename.endswith(".txt"):
f = open(filename, 'r')
text = f.read()
lines = [contractions.fix() for line in filename]
with open(filename, 'w') as out:
out.writelines(lines)
执行代码时,出现错误:
Traceback (most recent call last):
File "C:\Users\User\Desktop\replace contractions.py", line 15, in <module>
lines = [contractions.fix() for line in filename]
File "C:\Users\User\Desktop\replace contractions.py", line 15, in <listcomp>
lines = [contractions.fix() for line in filename]
TypeError: fix() missing 1 required positional argument: 's'
有谁知道这意味着什么以及如何解决它?