当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- “颜值经济”的野望:华熙生物净利率六连降,收购案遭上交所问询
- 合约交易系统开发|智能合约交易平台搭建
- 2019年的一个小目标,成为csdn的博客专家,纪念一下
- 中小微企业选择共享办公室怎么样?
- [event center azure event hub] interpretation of error information found in event hub logs
- Swagger 3.0 天天刷屏,真的香嗎?
- Programmer introspection checklist
- Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
- Brief introduction of TF flags
- Deep understanding of common methods of JS array
猜你喜欢
随机推荐
前端都应懂的入门基础-github基础
6.1.2 handlermapping mapping processor (2) (in-depth analysis of SSM and project practice)
I think it is necessary to write a general idempotent component
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
React design pattern: in depth understanding of react & Redux principle
数字城市响应相关国家政策大力发展数字孪生平台的建设
What problems can clean architecture solve? - jbogard
Network security engineer Demo: the original * * is to get your computer administrator rights! 【***】
一篇文章带你了解CSS3圆角知识
Vue.js Mobile end left slide delete component
比特币一度突破14000美元,即将面临美国大选考验
华为云“四个可靠”的方法论
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
5.4 static resource mapping
Python + appium automatic operation wechat is enough
[event center azure event hub] interpretation of error information found in event hub logs
前端基础牢记的一些操作-Github仓库管理
What is the difference between data scientists and machine learning engineers? - kdnuggets
axios学习笔记(二):轻松弄懂XHR的使用及如何封装简易axios