python将txt文件读取为字典的示例

时间:2021-01-20 04:16:52
【文件属性】:
文件名称:python将txt文件读取为字典的示例
文件大小:32KB
文件格式:PDF
更新时间:2021-01-20 04:16:52
python python实例 字典 如下所示: # -*- coding: utf-8 -*- # @Time :18-8-2 下午3:23 import sys reload(sys) sys.setdefaultencoding('utf8') fp = open(file, r) sample = fp.readlines() result_list = [] # 创建一个空列表 with open('file', 'w') as f: for line in sample: result_dict = {} try: sample_ = line.split(' ')#按照空格进行文件中每一行的

网友评论