0
我正在尝试读取一个文本文件并将该文件的内容转换为拉丁文件的新文件。这里是我有:读取和写入文件
def pl_line(word):
statement = input('enter a string: ')
words = statement.split()
for word in words:
if len(word) <= 1:
print(word + 'ay')
else:
print(word[1:] + word[0] + 'ay')
def pl_file(old_file, new_file):
old_file = input('enter the file you want to read from: ')
new_file = input('enter the file you would like to write to: ')
write_to = open(new_file, 'w')
read_from = open(old_file, 'r')
lines = read_from.readlines()
for line in lines():
line = pl_line(line.strip('\n'))
write_to.write(line + '\n')
read_from.close()
write_to.close()
然而,当我运行它,我得到这个错误信息: 类型错误:“名单”对象不是可调用
如何提高我的代码的任何想法?
你是对的,我已经编辑我原来的问题与我提出了与 – holaprofesor
问题的新错误消息调用'lines'( 'for'子句中的括号)。通过阅读整个回溯过程,你可以很容易地发现这一点;它会指向堆栈中发生错误的任何代码的行号。从最后列出的代码地方开始,如果您没有看到问题的原因,请按照回溯的方式进行操作。 –