Is it possible to print all the modules imported in a python script?

0 votes
I have imported a few modules in my python script. Now I want to print all the modules that are imported in my script. How to do it?
Jul 3 in Python by Arvind
• 2,760 points
25 views

1 answer to this question.

0 votes

Since I am using Python 3.6, I can answer from that perspective. You can refer to the following code to solve your problem

from modulefinder import ModuleFinder
finder = ModuleFinder()
finder.run_script("script.py")
for name, mod in finder.modules.items():
    print(name)

This code will print all modules loaded by script.py.

answered Jul 3 by Neel
• 2,730 points

Related Questions In Python

0 votes
1 answer

Is it possible in Python requests to print entire HTTP request?

A better idea is to use the ...READ MORE

answered Nov 26, 2018 in Python by Nymeria
• 3,520 points
50 views
0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24 in Python by Anjali
38 views
+1 vote
1 answer

is it possible to compare a values to a backslash in Python?

The backslash "\" character is used to ...READ MORE

answered Jun 28 in Python by Neel
• 2,730 points
27 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 175 views
+4 votes
6 answers
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26 in Python by Neel
• 2,730 points
42 views
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15 in Python by Neel
• 2,730 points
21 views