sách gpt4 ăn đã đi

python - 将文本附加到文件?

In lại 作者:太空狗 更新时间:2023-10-29 21:22:52 24 4
mua khóa gpt4 giày nike

<分区>

  1. 如何检查文件是否存在?
  2. 如何将文本附加到文件?

我知道如何创建文件,但在这种情况下,它会覆盖所有数据:

import io

with open('text.txt', 'w', encoding='utf-8') as file:
file.write('text!')

hiện hữu *nix 中我可以这样做:

#!/bin/sh

if [ -f text.txt ]
#If the file exists - append text
then echo 'text' >> text.txt;

#If the file doesn't exist - create it
else echo 'text' > text.txt;
fi;

24 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress