Hello. 2008/7/16 zhw <[EMAIL PROTECTED]>: > On 7月16日, 下午5时35分, Ben Finney <[EMAIL PROTECTED]> > wrote: >> zhw <[EMAIL PROTECTED]> writes: >> > Here is a example that I want to complete: >> > >>> import sys, new >> > >>> context={"name":"david", "sex":"male"} >> >> Here you have a set of values addressible by name. >> >> > >>> sys.modules["foo"] = new.module("foo") >> >> Why do you believe you need to create a module object? >> >> > >>> import foo >> > >>> for attr in context: >> > setattr(foo, attr, context[attr]) >>
Forgetting these considerations (I agree with Ben, though), your error is trying to use an 'import *' inside a function. You should take it outside the function, and try to run it again. >> >> > >>> def bar(): >> > # here is a error >> > # import * only allowed at module level >> > from foo import * >> > print name, sex >> There are different import statements you can use in Python. I recommend you to take a look at the tutorial to learn about the differences between them: http://docs.python.org/tut/node8.html Good luck. -- http://mail.python.org/mailman/listinfo/python-list