Python 3.x Python-regex在文件的每一行上

Python 3.x Python-regex在文件的每一行上,python-3.x,regex,Python 3.x,Regex,我有几个*.txt文件,每行包含几个句子。括号内有一些文字。我想删除它们,包括括号,并将它们放入新文件中,以新行分隔。到目前为止我都试过了 import re import glob with open('output.txt', 'w', encoding='utf-8') as out_file: for file in glob.glob('*.txt'): with open(file, 'r') as in_file: for line

我有几个
*.txt
文件,每行包含几个句子。括号内有一些文字。我想删除它们,包括括号,并将它们放入新文件中,以新行分隔。到目前为止我都试过了

import re
import glob

with open('output.txt', 'w', encoding='utf-8') as out_file:
    for file in glob.glob('*.txt'):
        with open(file, 'r') as in_file:
            for line in in_file:
                out_file(re.sub(r'\([^)]*\)', '', line))
                out_file('\n')
在执行过程中,我遇到以下错误:

TypeError: '_io.TextIOWrapper' object is not callable

out_文件不是一个可以“调用”的函数。您需要调用它的方法
write
。 改变

out_file(re.sub(r'\([^)]*\)', '', line))
out_file('\n')
out_file.write(re.sub(r'\([^)]*\)', '', line))
out_file.write('\n')