Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12442
| Date | 2011-08-30 11:19 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Returning a value from exec or a better solution |
| References | (2 earlier) <CAG5udOh1+oE4g9Frjp3pucbHUtWcN34KK35a-Xs2YqkZH9X5=w@mail.gmail.com> <CAJ6cK1ZSQJyPqOjU+TSR8mmsXWNoD9FJ2dvuQsAVEJHAWYrjHg@mail.gmail.com> <CAG5udOiOAge3uHrGSDTZ412GAg+CC-6u8iGOyJ0Lnf3HnwUVzA@mail.gmail.com> <Xns9F515822D92CrtwfreenetREMOVEcouk@80.91.229.10> <CAG5udOgxSmQrVOm+fPO_wsJsDLeR6jie0AgJFvauODd+2eA21g@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.577.1314727377.27778.python-list@python.org> (permalink) |
Jack Trades wrote: > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? Because the implementation will add things before the exec is processed. Then when the exec actually runs, any assignments, definitions, etc, from the user supplied string will be added. > I spoke a bit too soon with the "works flawlessly" post. In addition to > your issue, there is also the problem that supplying an empty > environment does not allow the user to call necessary functions (like > scheme_eval). So, just like an implementation, add the functions to the CapturingDict before the exec. One thing to keep in mind: the CapturingDict only remembers the *last* thing created/assigned... so if the user code has more than one def/class/name assignment, you won't have ready access to the first items, only that last one. ~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Returning a value from exec or a better solution Ethan Furman <ethan@stoneleaf.us> - 2011-08-30 11:19 -0700
csiph-web