欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AttributeError: 'tuple' object has no attribute 'writelines'

程序员文章站 2022-05-27 11:51:28
...
new_file = ('./data/es.txt', 'w')
new_file.writelines('date' + lines[3][:-1] + ';DEL' + lines[3][-1])



Traceback (most recent call last):

  File "<ipython-input-35-b6e2c5c19dbf>", line 1, in <module>
    new_file.writelines('date' + lines[3][:-1] + ';DEL' + lines[3][-1])

AttributeError: 'tuple' object has no attribute 'writelines'

报错的原因:
因为new_file并没有open文件,需改为

new_file = open('./data/es.txt', 'w')