How do I know the location of the library that I am loading in Python?

import ABC loads ABC from somewhere. How can I find out somewhere?

I can check the paths sys.pathone by one, but I wonder if I can find it in Python.

Additional questions

  • When I load a library with 'from ABC import *', how can I find out where the ABC is?
  • Can the "xyz class" know where it is when it is called?
+3
source share
1 answer
>>> import abc
>>> abc.__file__
'C:\\Program Files\\Python31\\lib\\abc.py'

See docs .

For a more thorough check, you can use inspectmodule:

>>> import inspect
>>> from abc import *
>>> inspect.getfile(ABCMeta)
'C:\\Program Files\\Python31\\lib\\abc.py'
+12
source

Source: https://habr.com/ru/post/1764690/


All Articles