当前位置:网站首页>Python saves the list data
Python saves the list data
2020-11-06 01:27:00 【Elementary school students in IT field】
For a list a[]:
preservation
filename = open(‘a.txt’, ‘w’)
for value in a:
filename.write(str(value))
filename.close()
Read
f= open(“a.txt”,“r”)
a = f.read()
f.close()
Although this method takes up less space , But the original list Format will be broken . You can also use the following method for this purpose , This method can keep list Original format .
preservation
import numpy as np
a=np.array(a)
np.save(‘a.npy’,a) # Save as .npy Format
Read
a=np.load(‘a.npy’)
a=a.tolist()
ps:
If it reads .txt The document is in Chinese , You need to add the following :
readme = pd.read_csv(‘ Read me .txt’,sep=’:’,encoding=“utf-8”, engine=‘python’,header=None)
readme = np.array(readme)
版权声明
本文为[Elementary school students in IT field]所创,转载请带上原文链接,感谢
边栏推荐
- Classical dynamic programming: complete knapsack problem
- 6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
- 华为云“四个可靠”的方法论
- EOS创始人BM: UE,UBI,URI有什么区别?
- The road of C + + Learning: from introduction to mastery
- Working principle of gradient descent algorithm in machine learning
- PN8162 20W PD快充芯片,PD快充充电器方案
- OPTIMIZER_ Trace details
- Skywalking series blog 5-apm-customize-enhance-plugin
- Brief introduction of TF flags
猜你喜欢

Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的

I'm afraid that the spread sequence calculation of arbitrage strategy is not as simple as you think

JVM memory area and garbage collection

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

合约交易系统开发|智能合约交易平台搭建

一篇文章带你了解CSS3圆角知识

The road of C + + Learning: from introduction to mastery

Troubleshooting and summary of JVM Metaspace memory overflow

Existence judgment in structured data

Summary of common algorithms of linked list
随机推荐
Not long after graduation, he earned 20000 yuan from private work!
6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
ES6学习笔记(五):轻松了解ES6的内置扩展对象
How to become a data scientist? - kdnuggets
Using Es5 to realize the class of ES6
一篇文章带你了解CSS 渐变知识
vue任意关系组件通信与跨组件监听状态 vue-communication
Common algorithm interview has been out! Machine learning algorithm interview - KDnuggets
每个前端工程师都应该懂的前端性能优化总结:
一篇文章教会你使用HTML5 SVG 标签
I'm afraid that the spread sequence calculation of arbitrage strategy is not as simple as you think
Python Jieba segmentation (stuttering segmentation), extracting words, loading words, modifying word frequency, defining thesaurus
前端工程师需要懂的前端面试题(c s s方面)总结(二)
In order to save money, I learned PHP in one day!
Advanced Vue component pattern (3)
Architecture article collection
The practice of the architecture of Internet public opinion system
Filecoin最新动态 完成重大升级 已实现四大项目进展!
Elasticsearch 第六篇:聚合統計查詢
中小微企业选择共享办公室怎么样?