替换收缩TypeError:fix()缺少1个必要的位置参数:' s'

时间:2018-04-20 10:21:40

标签: python

我有一个代码用文本文件的扩展(例如没有)替换单词中的收缩(例如,没有)。

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'

有谁知道这意味着什么以及如何解决它?

0 个答案:

没有答案