Accessing global namespace

Bob Gailer bgailer at alum.rpi.edu
Mon Oct 6 15:37:52 EDT 2003


At 04:27 AM 10/6/2003, =?iso-8859-9?Q?Tongu=E7?= Yumruk wrote:

>I'm trying to build a completely plug-in based system. One of my
>problems is importing a package dynamically. I'm trying to emulate the
>import command. The __import__() function or imp module doesn't help me
>much because they only return the module.

How about:

modName = 're' # for example
mod = __import__(modName )
exec modName + '=' + mod

>I want to register the module
>with it's name in the current namespace. I can do it by:
>
>         globals()[module_name] = __import__(module_name)
>
>But I don't think it's a good thing to access the global namespace
>directly. I prefer using setattr() but I cannot access the current
>namespace as an object I want something like
>
>         setattr(__main__,__import__(module_name))
>
>Is that possible? I'm using Python 2.1 on Debian Woody
>
>--
>Love, Respect, Linux
>############################################################################
>         "Has anyone had problems with the computer accounts?"
>         "Yes, I don't have one."
>         "Okay, you can send mail to one of the tutors ..."
>                 -- E. D'Azevedo, Computer Science 372
>############################################################################
>Tonguç Yumruk
>
>--
>http://mail.python.org/mailman/listinfo/python-list
>
>
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


More information about the Python-list mailing list