Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111994

Re: `exec`-based routine crashes app upon migration from 3.4.3 to python 3.5.2.

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: `exec`-based routine crashes app upon migration from 3.4.3 to python 3.5.2.
Date 2016-07-28 16:46 -0400
Message-ID <mailman.9.1469738797.6033.python-list@python.org> (permalink)
References <CAPKUSf6241yGYgVag-+P_Tob_Jq_UMWCbS6TGafYk2OVXvdOSw@mail.gmail.com> <1469738793.69613.679743369.5667BF8D@webmail.messagingengine.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: `exec`-based routine crashes app upon migration from 3.4.3 to python 3.5.2. Random832 <random832@fastmail.com> - 2016-07-28 16:46 -0400

csiph-web