w+ 和 r+的差别不难理解。还有a+
+同一时候读写,就可以读又可写,边写边读、边读边写,不用flush,用seek 和 tell可測得。
+同一时候读写,就可以读又可写,边写边读、边读边写,不用flush,用seek 和 tell可測得。
fp = open("a.txt", "a+", 0) print 'open',fp.tell() x = fp.read() print 'open read()',fp.tell() print x fp.write("123456 ") print 'write 1-6',fp.tell() x = fp.read() print "first read ",x fp.seek(0) x = fp.read() print "second read ", x,fp.tell() fp.close()第一次执行时的结果是:
open 0 open read() 0 write 1-6 8 first read second read 123456 8第二次执行时的结果是
open 0 open read() 8 123456 write 1-6 16 first read second read 123456 123456 16