0

I'm testing in Ipython and want to acknowledge of modules and packages already imported,

Firstly I tried locals and globals,

In [22]: len(globals())
Out[22]: 46

In [23]: len(locals())
Out[23]: 48

I have to lookup manually.

How to list the imported modules exclusively?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138

2 Answers2

1

I think what you want is just:

print(dir())

for example

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print(dir())
['__builtins__', '__doc__', '__name__', '__package__']
>>> import csv
>>> import json
>>> print(dir())
['__builtins__', '__doc__', '__name__', '__package__', 'csv', 'json']
>>> 
TrewTzu
  • 1,110
  • 2
  • 11
  • 27
1

the following code works

import sys
print([i for i in globals() if i in sys.modules.keys()])
rawwar
  • 4,834
  • 9
  • 32
  • 57