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'子句中的括號)。通過閱讀整個回溯過程,你可以很容易地發現這一點;它會指向堆棧中發生錯誤的任何代碼的行號。從最後列出的代碼地方開始,如果您沒有看到問題的原因,請按照回溯的方式進行操作。 –