这在我的csv文件中:
{'Name': 'The Hero', 'Min Damage': 2, 'Max Damage': 4, 'Defence': 1, 'HP': 20, 'Inventory': [], 'fought': False, 'Y': 1, 'X': 0}
这就是我试图带出字典的
def resumegame():
filename = 'C:/test/savegame.csv'
if not os.path.isfile(filename):
return {}
with open(filename) as ifh:
return dict(line.split() for line in ifh)
答案 0 :(得分:0)
您可以使用yaml模块
import yaml
def resumegame():
filename = 'C:/test/savegame.csv'
if not os.path.isfile(filename):
return {}
with open(filename) as ifh:
return yaml.load(ifh)