文章目录
一、回顾案例
def txt_writer():
"""写文件"""
with open('data.txt', 'w', encoding='utf8') as f:
f.write('武汉加油,中国加油!\n')
lines =[
'地址:北京市海淀区\n',
'QQ: 123422343\n',
'网址:http;//80s.com\n'
]
f.writelines(lines)
def txt_read():
"""读文件"""
with open('data.txt', 'r', encoding='utf8') as f:
for line in f:
print(line, end='')
if __name__ == '__main__':
txt_writer()
txt_read()
武汉加油,中国加油!
地址:北京市海淀区
QQ: 123422343
网址:http;//80s.com
二、csv文件读取
1.基本读取
2.namedtuple
3.读取csv到字典表
三、csv文件写入
1.以列表形式写入
接着读取写入的csv
若修改第7行为DictReader()变成字典表读取
2.以字典表形式写入
四、json文件
1.json文件读写
将json文件还原
2.json文档写入与读取
3.json文件类型差异
五、excel文件读取
1.读取excel中的工作薄
2.数据读取