ITPub博客

首页 > 应用开发 > > Python中关于用eval转换字符串

Python中关于用eval转换字符串

作者:huzhizhong 时间:2019-09-03 10:20:00 0 删除 编辑

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    107
  • 访问量
    922