Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111990
| From | Chris Angelico <rosuav@gmail.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-29 04:40 +1000 |
| Message-ID | <mailman.6.1469731262.6033.python-list@python.org> (permalink) |
| References | <CAPKUSf6241yGYgVag-+P_Tob_Jq_UMWCbS6TGafYk2OVXvdOSw@mail.gmail.com> <CAPTjJmqjVR6Q_LSNnx27uP5z6JmqSLrNTp_WjtP-mNCeXH9stg@mail.gmail.com> |
On Fri, Jul 29, 2016 at 1:47 AM, Enjoys Math <enjoysmath@gmail.com> wrote:
> I've manually set breakpoints and traced this app crash back to this
> function:
>
> def loadLSobjsOfType(self, objType, listJ):
> if listJ != None:
> for objJ in listJ:
> _locals = locals()
> exec('obj = ' + objType + '(self)', None, _locals)
> obj = _locals['obj']
> obj.loadJson(objJ)
> self.addLSobjOfType(objType, obj)
>
> when breakpoints are set on `obj=_locals['obj']` my wingware debugger kicks
> in and throws a KeyError exeption.
>
> So what's the proper way to get the return value of an exec call when there
> is one?
(Side point: Be aware that it's perfectly legal for a Python
interpreter to make mutations to locals() actually significant. You're
safe here, but just make sure that can't ever bite you.)
By the look of things, you're executing code using a locals but no
globals, and it's executing code at the global scope. Can you simply
remove the 'None' parameter, and thus make _locals be the exec'd
code's locals AND globals both?
Incidentally, what exactly is objType? By the name, I'd suspect that
it's a simple identifier, in which case I would strongly recommend not
using exec at all, but just looking up that name in some dictionary
(maybe globals()??) and calling the result. It'd be a lot simpler and
more efficient.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: `exec`-based routine crashes app upon migration from 3.4.3 to python 3.5.2. Chris Angelico <rosuav@gmail.com> - 2016-07-29 04:40 +1000
csiph-web