Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111994 > unrolled thread
| Started by | Random832 <random832@fastmail.com> |
|---|---|
| First post | 2016-07-28 16:46 -0400 |
| Last post | 2016-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.
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
| From | Random832 <random832@fastmail.com> |
|---|---|
| Date | 2016-07-28 16:46 -0400 |
| Subject | Re: `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
Back to top | Article view | comp.lang.python
csiph-web