python保存数据到本地文件的方法
作者:rosefun96 时间:2023-10-01 20:59:53
1、保存列表为.txt文件
#1/list写入txt
ipTable = ['158.59.194.213', '18.9.14.13', '58.59.14.21']
fileObject = open('sampleList.txt', 'w')
for ip in ipTable:
fileObject.write(ip)
fileObject.write('\n')
fileObject.close()
2、字典保存
#2/dict写入json
import json
dictObj = {
'andy':{
'age': 23,
'city': 'shanghai',
'skill': 'python'
},
'william': {
'age': 33,
'city': 'hangzhou',
'skill': 'js'
}
}
jsObj = json.dumps(dictObj)
fileObject = open('jsonFile.json', 'w')
fileObject.write(jsObj)
fileObject.close()
来源:https://blog.csdn.net/rosefun96/article/details/78877452
标签:python,数据,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python定时关机小脚本
2022-09-24 23:38:21
Python不使用int()函数把字符串转换为数字的方法
2022-04-22 02:32:33
详解python之配置日志的几种方式
2022-11-02 14:32:30
如何使用django的MTV开发模式返回一个网页
2023-07-04 21:47:06
![](https://img.aspxhome.com/file/2023/9/75139_0s.jpg)
python使用递归的方式建立二叉树
2021-07-07 23:47:18
![](https://img.aspxhome.com/file/2023/7/120367_0s.png)
启动targetcli时遇到错误解决办法
2023-03-20 05:59:43
Python使用os模块实现更高效地读写文件
2021-08-11 00:41:39
![](https://img.aspxhome.com/file/2023/3/117923_0s.png)
解决linux下使用python打开terminal时报错的问题
2022-10-06 10:46:25
asp如何读取服务器上的驱动器?
2009-11-18 20:50:00
Python爬虫信息输入及页面的切换方法
2023-08-02 17:33:33
火遍全网的Python二次元特效轻松掌握
2022-01-29 22:01:32
![](https://img.aspxhome.com/file/2023/6/107066_0s.png)
php获取referer防非法访问
2023-08-20 11:30:58
关于adfuller函数返回值的参数说明与记录
2023-03-07 13:33:14
读写xml文件的2个小函数
2007-08-23 12:59:00
Python全栈之学习HTML
2023-12-05 14:56:55
![](https://img.aspxhome.com/file/2023/0/101270_0s.png)
Python数据分析之Matplotlib数据可视化
2022-03-05 06:37:48
![](https://img.aspxhome.com/file/2023/0/103160_0s.png)
python集合的创建、添加及删除操作示例
2022-07-09 13:29:38
opencv+python实现鼠标点击图像,输出该点的RGB和HSV值
2023-05-16 13:37:20
![](https://img.aspxhome.com/file/2023/1/69471_0s.jpg)
Python把图片转化为pdf代码实例
2021-04-05 19:06:36
Python3中的真除和Floor除法用法分析
2023-10-11 09:01:45