Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12430
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'brilliant': 0.09; 'globals': 0.09; 'received:188.220': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.15; 'much!': 0.15; '1",': 0.16; 'val': 0.16; '>>>': 0.18; 'wrote': 0.20; 'function': 0.27; 'definition': 0.30; 'key,': 0.30; 'class': 0.30; 'to:addr:python- list': 0.33; '...': 0.34; 'header:User-Agent:1': 0.34; '(as': 0.34; 'header:X-Complaints-To:1': 0.35; 'thank': 0.35; 'received:org': 0.38; 'subject:: ': 0.39; 'user': 0.39; 'to:addr:python.org': 0.39; 'skip:d 20': 0.39; 'subject:from': 0.40; 'skip:n 30': 0.62; 'received:188': 0.68; 'want,': 0.71; 'locals': 0.84; 'received:bethere.co.uk': 0.84; 'subject:value': 0.84; 'subject:better': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Rob Williscroft <rtw@rtw.me.uk> |
| Subject | Re: Returning a value from exec or a better solution |
| Date | Tue, 30 Aug 2011 07:37:37 +0000 (UTC) |
| References | <CAG5udOg=GtFGPmTB=1OJNvNRPdYUcxDoKN1WJQMOMv9gx0+fZA@mail.gmail.com> <Xns9F50BCB7B5708rtwfreenetREMOVEcouk@80.91.229.10> <CAG5udOh1+oE4g9Frjp3pucbHUtWcN34KK35a-Xs2YqkZH9X5=w@mail.gmail.com> <CAJ6cK1ZSQJyPqOjU+TSR8mmsXWNoD9FJ2dvuQsAVEJHAWYrjHg@mail.gmail.com> <CAG5udOiOAge3uHrGSDTZ412GAg+CC-6u8iGOyJ0Lnf3HnwUVzA@mail.gmail.com> |
| X-Gmane-NNTP-Posting-Host | 188-220-43-229.zone11.bethere.co.uk |
| User-Agent | Xnews/5.04.25 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.565.1314689874.27778.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1314689874 news.xs4all.nl 2403 [2001:888:2000:d::a6]:51050 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12430 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Returning a value from exec or a better solution Rob Williscroft <rtw@rtw.me.uk> - 2011-08-30 07:37 +0000
csiph-web