__file__属性介绍
1. 获取当前文件绝对路径
import os print(__file__) print(os.path.basename(__file__))
得到输出:
e:\python\workspace\Mooc\test.py
test.py
2. 获取模块(或包)文件所在的具体存储位置
import os print(os.__file__)
得到输出:
D:\Program Files (x86)\Python3.6.5\lib\os.py
1. 获取当前文件绝对路径
import os print(__file__) print(os.path.basename(__file__))
得到输出:
e:\python\workspace\Mooc\test.py
test.py
2. 获取模块(或包)文件所在的具体存储位置
import os print(os.__file__)
得到输出:
D:\Program Files (x86)\Python3.6.5\lib\os.py