Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Introspect imports from module

Thread Tools

Introspect imports from module

Bastian Ballmann
Posts: n/a
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
print name

return old_import(name, globals, locals, fromlist)

__builtin__.__import__ = import_hook

Any suggestions how I could just get the import of
Thanks && have a nice day!

Bastian Ballmann / Web Developer
Notch Interactive GmbH / Badenerstrasse 571 / 8048 Z├╝rich
Phone Phone +41 44 297 17 17 /

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Introspect imports from module Bastian Ballmann Python 0 06-21-2012 01:16 PM
Dynamic imports + relative imports in Python 3 zildjohn01 Python 0 02-22-2011 05:24 PM
Imports System.Data or Imports System.Data.SqlClient? Albert ASP .Net 4 07-10-2008 09:00 AM
Introspect the class name of object? Davy Python 1 11-22-2007 04:03 AM
[Rails] Introspect "not null" for a Column? Gavin Kistner Ruby 0 04-04-2005 02:03 PM