当前位置:网站首页>python 保存list数据
python 保存list数据
2020-11-06 01:27:00 【IT界的小小小学生】
对于一个列表a[]:
保存
filename = open(‘a.txt’, ‘w’)
for value in a:
filename.write(str(value))
filename.close()
读取
f= open(“a.txt”,“r”)
a = f.read()
f.close()
以上这种方法虽然占用空间小,但是原来的list格式会被破坏。为此也可以用以下发方法,此方法可以保留list原格式。
保存
import numpy as np
a=np.array(a)
np.save(‘a.npy’,a) # 保存为.npy格式
读取
a=np.load(‘a.npy’)
a=a.tolist()
ps:
如果读取的.txt文件是中文名,需要加以下内容:
readme = pd.read_csv(‘读我.txt’,sep=’:’,encoding=“utf-8”, engine=‘python’,header=None)
readme = np.array(readme)

版权声明
本文为[IT界的小小小学生]所创,转载请带上原文链接,感谢
https://vip01.blog.csdn.net/article/details/93488969
边栏推荐
猜你喜欢
随机推荐
NodeJs爬虫抓取古代典籍,共计16000个页面心得体会总结及项目分享
结构化数据中的存在判断问题
Using lime to explain black box ML model
keras model.compile损失函数与优化器
写一个通用的幂等组件,我觉得很有必要
Probabilistic linear regression with uncertain weights
Working principle of gradient descent algorithm in machine learning
普通算法面试已经Out啦!机器学习算法面试出炉 - kdnuggets
《Google软件测试之道》 第一章google软件测试介绍
使用ES5实现ES6的Class
7.3.1 file upload and zero XML registration interceptor
nlp模型-bert从入门到精通(二)
企业数据库的选择通常由系统架构师主导决策 - thenewstack
TF flags的简介
想要做读写分离,送你一些小经验
网络安全工程师演示:原来***是这样获取你的计算机管理员权限的!【***】
9.2.1 xmlconfigbuilder constructor (xmlconfigbuilder analysis) - SSM in depth analysis and project practice
5.4 静态资源映射 -《SSM深入解析与项目实战》
自然语言处理之分词、命名主体识别、词性、语法分析-stanfordcorenlp-NER(二)
Electron应用使用electron-builder配合electron-updater实现自动更新