How to know the location of the library that I load in Python?
import ABC loads ABC from somewhere. How can I know the 'somewhere'?
I may be 开发者_开发知识库able to check the paths in sys.path
one by one, but I wonder if I can find it in Python.
More Questions
- When I load library with 'from ABC import *', how can I know where ABC is located?
- Can 'class xyz' know where it is located when it is called?
>>> import abc
>>> abc.__file__
'C:\\Program Files\\Python31\\lib\\abc.py'
See docs.
for more thorough inspection you could use inspect
module:
>>> import inspect
>>> from abc import *
>>> inspect.getfile(ABCMeta)
'C:\\Program Files\\Python31\\lib\\abc.py'
精彩评论