当前位置:网站首页>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
边栏推荐
- 技术总监,送给刚毕业的程序员们一句话——做好小事,才能成就大事
- 想要做读写分离,送你一些小经验
- 8.1.2 handling global exceptions through simplemappingexceptionresolver
- Using lime to explain black box ML model
- Working principle of gradient descent algorithm in machine learning
- 9.2.3 loadcustomvfs method (XML configuration builder analysis) - SSM in depth analysis and project practice
- 数据科学家与机器学习工程师的区别? - kdnuggets
- 微信小程序:防止多次点击跳转(函数节流)
- 企业数据库的选择通常由系统架构师主导决策 - thenewstack
- 互联网 舆情系统的架构实践
猜你喜欢
随机推荐
Anomaly detection method based on SVM
用TensorFlow预测纽约市AirBnB租赁价格
5.5 ControllerAdvice注解 -《SSM深入解析与项目实战》
被产品经理怼了,线上出Bug为啥你不知道
Skywalking系列博客5-apm-customize-enhance-plugin插件使用教程
leetcode之赎金信
Dapr实现分布式有状态服务的细节
结构化数据中的存在判断问题
【C/C++ 2】Clion配置与运行C语言
8.1.2 handling global exceptions through simplemappingexceptionresolver
【无思路题目】1636. 按照频率将数组升序排序
Azure DevOps 扩展之 Hub 插件的菜单权限控制配置
【C/C++ 1】Clion配置与运行C语言
Gradient understanding decline
Vue 3 响应式基础
9.2.1 xmlconfigbuilder constructor (xmlconfigbuilder analysis) - SSM in depth analysis and project practice
聆听无声的话语:手把手教你用ModelArts实现手语识别
什么是无副作用的函数方法?如何取名? - Mario
自然语言处理之分词、命名主体识别、词性、语法分析-stanfordcorenlp-NER(二)
tensorflow之tf.tile\tf.slice等函数的基本用法解读







