Python 代码:在桌面上创建 10 个空文本文件
import os
获取桌面路径
desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
创建 10 个空的文本文档
for i in range(1, 11): file_name = f'test{i}.txt' file_path = os.path.join(desktop_path, file_name) with open(file_path, 'w') as f: pass
print('已创建 10 个空的文本文档')
原文地址: https://www.cveoy.top/t/topic/mXpn 著作权归作者所有。请勿转载和采集!