我需要打开一个文件来读取每一行,然后在每一行的末尾添加一个字符串。然后,将打开的文件写回新行。
number = 0
with open("test_openFile.txt", "r+b") as the_file:
for line in the_file:
print (line)
type(line)
line = line.strip('\n') + "\t" + str(number)
number += 1
the_file.write(line)
但是,我得到了:
line = line.strip('\n')
TypeError: Type str doesn't support the buffer API
任何帮助,将不胜感激 !