我需要在名为“dir”的目录中编写一个名为copy_success.txt的文本文件,内容为“Copy done”,有人可以建议怎么做吗?
答案 0 :(得分:0)
import os
cl_dir = 'dir'
try:
os.mkdir(cl_dir)
except OSError:
pass # os.mkdir will raise an exception if there's the directory. Ignore that.
with open(os.path.join(cl_dir, 'copy_success.txt'), 'w') as f:
f.write('Copy done')