可能重复:
python open built-in function: difference between modes a, a+, w, w+, and r+?
try:
f = open("file.txt", "r")
try:
string = f.read()
line = f.readline()
lines = f.readlines()
finally:
f.close()
except IOError:
pass
try:
f = open("file.txt", "w")
try:
f.write('blah') # Write a string to a file
f.writelines(lines) # Write a sequence of strings to a file
finally:
f.close()
except IOError:
pass
您好,
这是我可以读写文件但我想打开文件一次并在python中执行读写操作的模式