
Python将数据存储到本地文件的技巧
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本篇文章主要介绍如何使用Python语言高效地将数据保存至本地文件的方法和技巧,包括常用库的使用及注意事项。
1. 保存列表为.txt文件
```python
ipTable = [158.59.194.213, 18.9.14.13, 58.59.14.21]
with open(sampleList.txt, w) as fileObject:
for ip in ipTable:
fileObject.write(ip + \n)
```
2. 字典保存为json文件
```python
import json
dictObj = {andy: {age: 23, city: shanghai}}
with open(sampleDict.json, w) as fileObject:
json.dump(dictObj, fileObject)
```
全部评论 (0)
还没有任何评论哟~


