ERROR: AttributeError: '_io.TextIOWrapper' object has no attribute 'split'

ERROR: AttributeError: '_io.TextIOWrapper' object has no attribute 'split'

这是我的代码:

line = open('save_file.txt')

s = {}
(s['nome'], s['race'], s['classes'], s['FOR'], s['INT'], s['DES']) = line.split(";")

print("Nome: " + s['nome'])
print("Raça: " + s['race'])

我正在尝试打印 save_file 中的内容,但是当我启动程序时出现标题错误。有人可以帮忙吗? 感谢关注

open returns 文件对象,不是行。你需要像

这样的东西
f = open('save_file.txt')
for line in f:
   #do stuff