Python文件操作2

来源:互联网 发布:淘宝美工做什么工作的 编辑:程序博客网 时间:2024/06/16 13:34


文件操作:


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.encodingprint f.modeprint 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.pathif os.path.exists('hello.txt'):    os.remove('hello.txt')    print 'del'输出:a+0chejia['chejia\n', '123456\n']del

0 0
原创粉丝点击