Python: which modules were imported into my process?

How can I get a list of modules that have been imported into my process?

+3
source share
2 answers

sys.modules.values()... if you really need names for the modules, use sys.modules.keys ()

dir() not what you want.

>>> import re
>>> def foo():
...     import csv
...     fubar = 0
...     print dir()
...
>>> foo()
['csv', 'fubar'] # 're' is not in the current scope
>>>
+11
source

You can also start the interpreter with a parameter -vif you just want to see the imported modules (and the order of their import)

+4
source

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


All Articles