标签:序列 lin for nes 文件 rip 读写 初学 txt
文件读写:
with open(r‘f:\test\t1.txt‘,‘r‘) as f:
print f.read() 读
f.close() 关闭
with相当于try...catch;
按行读:
with open(r‘f:\test\t1.txt‘,‘r‘) as f:
for l in f.readlines():
print l.strip()
f.close()
写文件:
with open(r‘f:\test\t1.txt‘,‘w‘) as f:
f.write(‘abcde‘)
f.close()
序列化:
import cPickle as pickle 引入包
with open(r‘f:\test\t1.txt‘, ‘wb‘) as f:
dic = 10
pickle.dump(dic, f)
f.close()
with open(r‘f:\test\t1.txt‘, ‘rb‘) as f:
aa = pickle.load(f)
print(aa)
f.close()
标签:序列 lin for nes 文件 rip 读写 初学 txt
原文地址:https://www.cnblogs.com/jlyg/p/9141471.html