python 读写txt文件
读文件
#!/usr/bin/env python
#coding: utf-8
file=open('aa.txt'):
for line in file:
line=line.strip()
print line
写文件
#!/usr/bin/env python
#coding: utf-8
with open('test_w.txt', mode='a', encoding='utf8') as f:
lines = [
'this is my text for write,',
'hello world!',
'bye'
]
for line in lines:
if line:line=line+'\n'
f.write(line)
f.close()