python读取txt文件到字典
python读取txt文件到字典
python读取txt文件到字典
import os
fp = open("test.txt", "r")
sample = fp.readlines()
result_dict = {}
for line in sample:
print(line)
sample_ = line.split(' ')#按俩空格进行文件中每一行的切割
print(sample_)
print(sample_[0])
#sample_=['33\tInvasive\textended\n']
#sample_[0]=33 Invasive extended
result_dict[sample_[0].split('\t')[0]]=sample_[0].split('\t')[1]
print(result_dict)
#取去路径中文文件名,并去除后缀
path="F:\Desktop\Verification-Code-Recognition\test_image\ocgf.jpeg"
print(os.path.basename(path).split('.')[0])
最新文章
- 800余名中外专家学者齐聚无锡 共铸智联安全
- 移动互联网未来的发展趋势
- 盘点2012:软件定义网络风生水起
- 【Java】接口与继承
- Xmanager5 Passive 图形界面安装oracle,无法使用鼠标
- 箱型图盒图 jupyter Notebook
- Filter拦截过滤参数
- nginx 做均衡负载
- 使用Springboot实现Nginx均衡负载功能
- 三维偏序cdq分治
- 港湾公园 Haven Park for Mac(好玩的探索建造冒险游戏)
- 【消息中心】架构准备
- UDS服务简易教程
- 我的Hadoop安装流程
- 超好用的Redis管理及监控工具
- Retrofit 使用详解
- 用Python从零复现A星寻路算法