文件操作:
r 读
r+ 读写
w 写入 重新创建
w+ 读写入 重新创建
a 写入 追加 创建
a+ 读写 追加 创建
b 以二进制打开文件
U 支持所有换行符
f = file('hello.txt',"a+")
f.writelines('chejia\n')
f.writelines('123456\n')
f.flush()
f.seek(0)
print f.encoding
print f.mode
print f.tell()
print f.readline()
f.seek(0)
print f.readlines()
f.close()
#文件的赋值
src = file('hello.txt','r')
dst = file('hello word.txt','w')
dst.write(src.read())
dst.close()
src.close()
#文件的删除
import os.path
if os.path.exists('hello.txt'):
os.remove('hello.txt')
print 'del'
输出:
a+
0
chejia
['chejia\n', '123456\n']
del