Python 中list, dictionary 与 file相互操作
2013-07-10 15:45
295 查看
Python的list,dictionary可以写入file, 也可以从file中读取。
关于list:1)写入文件 self.existedBlog.write("your item data" + "\n")2)读取 self.existedBlog = open("existedBlog", "r+")
self.existedBlog.seek(0)
currentBlogs = self.existedBlog.readlines() print(currentBlogs)
3)文件内容: line1 line2 line3 line4
关于dictionay:1)写入文件 import json dict['authToken'] = "your dev auth token"file = open('config', "w+")
writer = json.JSONEncoder()
print(writer.encode(dict).strip("{}"))2)读取 import json
input_text = open('config').read()
input_json = "{%(input_text)s}" % vars()
reader = json.JSONDecoder()
config = reader.decode(input_json)
print(config)
3)文件内容:
"authToken":"your dev auth token",
"noteStoreUrl":"your store",
"blogType":"your blog api",
"username":"",
"password":"",
相关文章推荐
- Python 中list, dictionary 与 file相互操作
- Python 中list, dictionary 与 file相互操作
- Python的list、tuple、set、dictionary操作总结
- python的list之间相互赋值的陷阱
- 用list去初始化numpy的array数组 numpy的array和python中自带的list之间相互转化
- Python List 、 元组、字典操作
- python入门之列表list删除操作
- Python中list查询及所需时间计算操作示例
- python3 操作 redis List(列表) 实例 详解
- Python之文件与目录操作(os、zipfile、tarfile、shutil)
- C#数组,List,Dictionary的相互转换
- python List的一些相关操作
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- python中的list如何进行相减操作或者将list分片
- python基础(List,Dictionary,Random,循环,Lambda,Tumple)
- python中的List/列表的相关操作
- 一个list,一个数组,如何在相互比较之后进行一些操作
- Python学习笔记015——文件file的常规操作(二进制文件)
- Python中list的详细操作描述(举例说明)
- numpy.array和python中list的相互转化