Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12430 > unrolled thread
| Started by | Rob Williscroft <rtw@rtw.me.uk> |
|---|---|
| First post | 2011-08-30 07:37 +0000 |
| Last post | 2011-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.
Re: Returning a value from exec or a better solution Rob Williscroft <rtw@rtw.me.uk> - 2011-08-30 07:37 +0000
| From | Rob Williscroft <rtw@rtw.me.uk> |
|---|---|
| Date | 2011-08-30 07:37 +0000 |
| Subject | Re: 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.
Back to top | Article view | comp.lang.python
csiph-web