开发者

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

  1. When I load library with 'from ABC import *', how can I know where ABC is located?
  2. 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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜