python的内置属性__file__
python文件/模块都有一个内置属性file,属性的值是文件的位置,即绝对路径
例如:
import random
import os
#查看random模块的绝对路径
print(random.__file__)
#查看os模块是否有__file__属性:
[attr for attr in dir(os) if attr.startswith("__")]
#输出结果中有__file__属性
python文件/模块都有一个内置属性file,属性的值是文件的位置,即绝对路径
例如:
import random
import os
#查看random模块的绝对路径
print(random.__file__)
#查看os模块是否有__file__属性:
[attr for attr in dir(os) if attr.startswith("__")]
#输出结果中有__file__属性