Introspect imports from module

B

Bastian Ballmann

Hi all,

I am trying to write a function that returns a list of imports a given
module is doing. The "problem" is I dont want to get the imports of the
imports, but that's the case with my current solution.

import __builtin__
old_import = __builtin__.__import__

def import_hook(name, globals=None, locals=None, fromlist=None):
if fromlist:
for symbol in fromlist:
print name + "." + symbol
else:
print name

return old_import(name, globals, locals, fromlist)

__builtin__.__import__ = import_hook
import module.to.inspect

Any suggestions how I could just get the import of module.to.inspect?
Thanks && have a nice day!

Basti
--
Bastian Ballmann / Web Developer
Notch Interactive GmbH / Badenerstrasse 571 / 8048 Zürich
Phone Phone +41 44 297 17 17 / www.notch-interactive.com

CHECK OUR LATEST WORK: http://www.notch-interactive.com/projekte/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top