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


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

Re: Returning a value from exec or a better solution

Started byRob Williscroft <rtw@rtw.me.uk>
First post2011-08-30 07:37 +0000
Last post2011-08-30 07:37 +0000
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: Returning a value from exec or a better solution Rob Williscroft <rtw@rtw.me.uk> - 2011-08-30 07:37 +0000

#12430 — Re: Returning a value from exec or a better solution

FromRob Williscroft <rtw@rtw.me.uk>
Date2011-08-30 07:37 +0000
SubjectRe: Returning a value from exec or a better solution
Message-ID<mailman.565.1314689874.27778.python-list@python.org>
Jack Trades wrote in news:CAG5udOiOAge3uHrGSDTZ412GAg+CC-
6u8iGOyJ0Lnf3HnwUVzA@mail.gmail.com in gmane.comp.python.general:

>> >>> class CapturingDict(dict):
>> ...     def __setitem__(self, key, val):
>> ...         self.key, self.val = key, val
>> ...         dict.__setitem__(self, key, val)
>> ...
>> >>> c = CapturingDict()
>> >>> exec("def myfunction(x): return 1", c)
>> >>> c.key
>> 'myfunction'
>> >>> c.val
>> <function myfunction at 0x100634d10>
>>
>> HTH,
>>
>> --
>> Arnaud
>>
> 
> That's brilliant and works flawlessly.  Thank you very much!

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 ?

Rob.

[toc] | [standalone]


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


csiph-web