便捷的获取文件后缀名
import os
file_ext = os.path.splitext('./data/py/test.py')
front,ext = file_ext
print(front)
print(ext)
: import os
...: file_ext = os.path.split('./data/py/test.py')
...: ipath,ifile = file_ext
文件读写操作
import os
def mkdir(path):
isexists = os.path.exists(path)
if not isexists:
os.mkdir(path)
def openfile(filename):
f = open(filename)
filist = f.read()
f.close()
return filist # 返回读取内容
批量修改啊文件后缀
本例⼦使⽤Python的 os模块和 argparse模块,将⼯作⽬录 work_dir下所有后缀名为 old_ext的⽂
件修改为后缀名为 new_ext