Code redundancy

Andreas Löscher andreas.loescher at
Wed Apr 21 12:03:57 CEST 2010

You can do something like this:

>>> class A(): pass
>>> inst=A()
>>> exec("""
... a=1
... b=2
... c=3
... d=4
... """) in inst.__dict__
>>>  inst.a

This executes the Statement in the exec function and uses inst.__dict__
as namespace. But be aware, that this is not recommended. If you mess
with __dict__, you won't be able to replace it with some logic
(parameter) if you need to do something more than setting a variable.


More information about the Python-list mailing list