python文本读写数据

 # 写方法1
f = open('tmp.txt','w')
f.write('hello world')
f.close() # 写方法2
with open('tmp.txt','w') as f:
f.write('hello \n word') # 读
with open('tmp.txt', 'r') as f:
print(f.read()) # 逐行读
with open('tmp.txt','r') as f:
for line in f.readlines():
print(line.strip())#strip()去除空行
上一篇:看linux连接进程占用的实时流量iftop netatop NetHogs


下一篇:ansible工具