gpt4 book ai didi

python - 读写模式python

转载 作者:太空狗 更新时间:2023-10-29 19:32:28 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
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 中执行读写操作

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com