标签:操作 his ora 进制 this 文件操作 内容 line code
1. 可读可写 : r+ (读写)
1 #可读可写:r+ 写的内容在文件内容的尾部 2 3 f = open(‘file2‘,‘r+‘,encoding=‘utf-8‘) 4 for i in range(3): 5 print(f.readline()) 6 f.write(‘--------------------------233-------------------------------‘)
2.可写可读:w+ (写读)
1 # 写读模式:w+ 2 f = open(‘file3‘,‘w+‘,encoding=‘utf-8‘) 3 for i in range(3): 4 f.write(‘------------0---------go!\n‘) 5 print(f.tell()) 6 f.seek(10) 7 print(f.tell()) 8 f.write(‘This is is is is is so good!‘) 9 print(f.readlines()) 10 f.close()
3.追加读写:a+ (追加读写)
1 f = open(‘file5‘,‘a+‘,encoding=‘utf-8‘) 2 for i in range(5): 3 f.write(‘1------------------------go!\n‘) 4 print(f.tell()) 5 f.seek(10) 6 print(f.tell()) 7 f.write(‘-----------------end--------------------‘) 8 print(f.readlines())
4.二进制文件的读:rb、写:wb、追加:ab
1 #二进制文件的读 :rb 2 f = open(‘file5‘,‘ab‘) #rb wb ab 3 print(f.readlines()) 4 #二进制文件的写 :wb 5 f.write("oracle or mysql\n".encode()) 6 #二进制文件的追加 :ab 7 f.write(‘\ngood‘.encode())
标签:操作 his ora 进制 this 文件操作 内容 line code
原文地址:http://www.cnblogs.com/msl23/p/7241255.html