Python处理文件和路径相关

工具/版本

(1)安装环境:Windows7 64bit

(2)使用版本Python3.6

 

给出绝对路径,分解为文件路径和文件名

filename = os.path.basename(fileName1)
filepath = os.path.dirname(fileName1)

解析当前运行py文件名

PyPath = os.path.basename(sys.argv[0]).split(".")[0] + ".py"

猜你喜欢

转载自blog.csdn.net/samenmoer/article/details/82141619