python 删除本地文件兼容windows和linux

def del_local_file(file_pth, is_dir=False):
sysstr = platform.system()
# 删除本地文件
if not is_dir:
if sysstr == "Windows":
os.system('del /s/q %s' % file_pth)
elif sysstr == "Linux":
os.system('rm -rf %s' % file_pth)
else:
if sysstr == "Windows":
os.system('rd /s/q %s' % file_pth)
elif sysstr == "Linux":
os.system('rm -rf %s' % file_pth)
原文地址:https://www.cnblogs.com/fuchenjie/p/14602237.html