On Thu, Jul 28, 2016, at 11:47, Enjoys Math wrote: > So what's the proper way to get the return value of an exec call when > there is one?
Exec calls do not have return values. If you need to pass an object out of the exec call to the surrounding context, you can wrap it in an exception and throw it. class ObjectWrapperException(Exception): def __init__(self, obj): self.obj = obj super().__init__() code = 'obj = ' + objType + '(self)\nraise ObjectWrapperException(obj)' try: exec(code, None, _locals) except ObjectWrapperException as e obj = e.obj -- https://mail.python.org/mailman/listinfo/python-list