views:

65

answers:

1

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?
+12  A: 
>>> 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'
SilentGhost
Forgot the link to http://docs.python.org/reference/datamodel.html
S.Lott
thanks, S.Lott, added.
SilentGhost