python文件处理相关函数

  • 用open()创建文件

open('a.txt','wt')

  • 用exists()检查文件是否存在

os.path.exists()

  • 用isfile()检查是否为文件

os.path.isfile(name)

  • 用isdir()检查时候为文件夹

os.path.isdir(name)

  • 用copy()复制文件

import shutil
shutil.copy()

  • 用rename()重命名文件

import os
os.rename('a.txt','b.txt')

原文地址:https://www.cnblogs.com/everfight/p/python_os.html