有这么一个需求,你想从文件中读取字典,方法有很多,这里用的是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
1.理解Pythonic概念 Pythonic Tim Peters 的 <The Zen of Python>相信学过 Python 的都耳熟能详,在交互式环境中输入import this可以查看,其实有意思的是这段 Python 之禅的源码: d = {} for c in (65, 97): for i in range(26): d[chr(i+c)] = chr((i+13) % 26 + c) print "".join([d.get(c, c) for c i