摘要:
python中对文件和目录的操作主要用到两个模块:os 模块 和shutil 模块。一、对文件的操作: 1、创建文件 (1)方法一1 #创建空文件2 import os3 os.mknod("test.txt") (2) 方法二1 #直接打开一个文件,如果文件不存在则创建文件2 open("test.txt", 'w') 2、复制文件 (1)方法一:1 #oldfile和newfile都只能是文件2 import shutil3 shutil.copyfile("oldfile","newfile" 阅读全文