PYTHON将list或/dict对象写入txt/json文件
来源:互联网 发布:儿童英语配音软件 编辑:程序博客网 时间:2024/05/16 17:26
不能直接将list或dict对象进行写入,会出现typeError。
一、写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()
二、写dict对象到json文件
需要import json,将dict转为字符串后写入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()
0 0
- PYTHON将list或/dict对象写入txt/json文件
- Python打开文件,将list、numpy数组内容写入txt文件中
- Python打开文件,将list、numpy数组内容写入txt文件中
- python json 转 dict , list
- winform将List写入txt
- C++ 将文件夹中文件写入list.txt文件中
- python中对于json写入txt文件的编码问题
- python dict json读写文件
- python中list,str,json,dict使用
- 将list数据写入到txt中
- python读取.txt文件数据和将数据写入文件.txt
- python 写入、读取txt文件
- python读取 .txt 文本内容以及将程序执行结果写入txt文件
- Python读取指定路径所有.txt文件,将文件名写入.txt
- python中对dict或list等可变对象进行append操作
- Python之dict(或对象)与json之间的互相转化
- python json写入txt中文乱码
- MFC学习之 将 list 表里的信息写入.txt文本 和 .xls EXCEL 文件中
- RTMPDump
- hdu1233 还是畅通工程(prim算法)解题报告
- caffe study- AlexNet 之结构篇
- Stacks of Flapjacks
- 猴子背100根香蕉问题程序实现
- PYTHON将list或/dict对象写入txt/json文件
- 将滚动条(scrollbar)保持在最底部的方法
- codeproject 的精彩文章----对我有用
- 在线查android 源码
- @自定义注解
- Java Web学习总结(25)——MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建
- 网络安全协议比较(PKI SSH SSL SET)
- 如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access
- 大数据文件导入MySql处理方式