ast模块

Posted 梦轻尘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ast模块相关的知识,希望对你有一定的参考价值。

有这么一个需求,你想从文件中读取字典,方法有很多,这里用的是ast模块

import ast

with open("account","r",encoding="utf8") as read_file:
    data = ast.literal_eval(read_file.read())
    print(type(data))


##演示结果
C:\python3.5\python.exe D:/qq文件存放地/day9/FTP/测试/测试读取文件.py
<class ‘dict‘>

Process finished with exit code 0

  

以上是关于ast模块的主要内容,如果未能解决你的问题,请参考以下文章