Load objects using __import__
pavlovevidence at gmail.com
Tue Nov 21 15:04:40 CET 2006
> But when I load the object I get
> SyntaxError: invalid syntax
> c1 = <module 'project.I18n.models' from
It looks like you're running generated code somewhere, but passing the
module itself rather than the name of the module to the code generator
by mistake. Perhaps you're execing some code that you pass the module
name to? Something like this?
exec 'c1 = %s.Country(name="Afgahanstan")' % module_name
You seem to be erroneously using the module itself, not the module
That's about all I can help without more information.
P.S. if you are doing that, consider using getattr instead of exec.
c1 = getattr(module,Country)(name="Afgansitan")
More information about the Python-list