os.path.dirname()接口的具体介绍:
Python | os.path.dirname()-CSDN博客文章浏览阅读2次。Python3 os.path.dirname()接口实践记录https://blog.csdn.net/2301_80067028/article/details/134329160os.path.dirname(__file__)是获取py文件的路径名
Python3
# Python program to explain os.path.dirname(__file__) method
# importing os.path module
import os.path
print(os.path.dirname(__file__))
测试结果如下:
注意:
1. 在运行的时候如果没有输入py文件的路径名,则返回空
2. 在运行的时候如果输入py文件的路径名,则返回py文件的路径名