首页 > 应用开发 > > Python中关于用eval转换字符串
user_history.txt里存的是:
{'name': '电脑', 'price': 19999}{'name': '电脑', 'price': 19999}
with open("user_history.txt", "w+")as f2:
history = f2.read()
history = eval(history)
print(history)
当执行history = eval(history)这条语句时就会出错
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1446/viewspace-3164499/ ,如需转载,请注明出处,否则将追究法律责任。