[Baypiggies] how to programmatically invoke: from module import *
Tung Wai Yip
tungwaiyip at yahoo.com
Wed Mar 4 20:36:20 CET 2009
I end up writing something like this
mod = __import__(module_name,fromlist=['*'])
imported = dict((n,v) for n, v in vars(mod).items() if not
This code has not considered __all__.
The fromlist=['*'] argument in __import__() is rather surprising. It
doesn't really execute a "from module import *" as I expect. I still have
to do filtering manually. All it does is a subtle difference in the module
returned. In fact I can pass fromlist=['xxx'] and the result obtained
seems to be the same.
> vars(__import__('module')) should get you a dictionary close to what
> you desire. It may need tweaking because it does not apply the extra
> restrictions that "import *" does (__all__ and leading underscores).
> On Tue, Mar 3, 2009 at 9:55 AM, Tung Wai Yip <tungwaiyip at yahoo.com>
>> I always have some trouble in understanding the API for modules
>> like the __import__(). And this one I really need some help. How can I
>> programmatically invoke: from module import *? I want to put the
>> in a dictionary and pass it some other module.
>> Thank you,
>> Wai Yip
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
More information about the Baypiggies