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


Groups > comp.lang.python > #111994 > unrolled thread

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

Started byRandom832 <random832@fastmail.com>
First post2016-07-28 16:46 -0400
Last post2016-07-28 16:46 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

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

FromRandom832 <random832@fastmail.com>
Date2016-07-28 16:46 -0400
SubjectRe: `exec`-based routine crashes app upon migration from 3.4.3 to python 3.5.2.
Message-ID<mailman.9.1469738797.6033.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web