Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67112
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'dynamically': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'def': 0.12; 'wrote': 0.14; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sources.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'properly': 0.19; 'feb': 0.22; '>>>': 0.22; 'install': 0.23; 'fairly': 0.24; 'header': 0.24; 'source': 0.25; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; '+0100,': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'implemented': 0.33; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'version': 0.36; 'c++': 0.36; 'step': 0.37; 'to:addr:python-list': 0.38; 'generating': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'eventually': 0.60; 'happen': 0.63; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: exec and locals |
| Date | Wed, 26 Feb 2014 23:20:10 -0500 (EST) |
| Organization | news.gmane.org |
| References | <530de8ed$0$29985$c3e8da3$5496439d@news.astraweb.com> <mailman.7393.1393422407.18130.python-list@python.org> <530e8608$0$11113$c3e8da3@news.astraweb.com> |
| X-Gmane-NNTP-Posting-Host | dpc6744193198.direcpc.com |
| X-Newsreader | PiaoHong Usenet NewsReaders 1.36 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7403.1393474578.18130.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1393474578 news.xs4all.nl 2840 [2001:888:2000:d::a6]:42950 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:67112 |
Show key headers only | View raw
Steven D'Aprano <steve@pearwood.info> Wrote in message:
> On Wed, 26 Feb 2014 14:46:39 +0100, Peter Otten wrote:
>
>> Steven D'Aprano wrote:
>>
>>> I have to dynamically generate some code inside a function using exec,
>>> but I'm not sure if it is working by accident or if I can rely on it.
>>>
>> I eventually settled on some
> code that works something like this:
>
>
> def factory():
> blah blah blah
> try:
> exec("""def inner():
>
Before I would use exec, I'd look hard at either generating a
source file to import, or using a preprocessor. And if this
code was to be installed, make the version choice or the
preprocess step happen at install time.
I once implemented a system that generated 20k lines of C++ header
and sources. And the generated code was properly indented and
fairly well commented.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
exec and locals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-26 13:15 +0000
Re: exec and locals Chris Angelico <rosuav@gmail.com> - 2014-02-27 00:40 +1100
Re: exec and locals Peter Otten <__peter__@web.de> - 2014-02-26 14:46 +0100
Re: exec and locals Steven D'Aprano <steve@pearwood.info> - 2014-02-27 00:25 +0000
Re: exec and locals Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-27 16:34 +1300
Re: exec and locals Steven D'Aprano <steve@pearwood.info> - 2014-02-27 04:39 +0000
Re: exec and locals Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-28 00:29 +1300
Re: exec and locals Chris Angelico <rosuav@gmail.com> - 2014-02-27 22:41 +1100
Re: exec and locals Steven D'Aprano <steve@pearwood.info> - 2014-02-28 01:49 +0000
Re: exec and locals Dan Sommers <dan@tombstonezero.net> - 2014-02-27 03:47 +0000
Re: exec and locals Dave Angel <davea@davea.name> - 2014-02-26 23:20 -0500
Re: exec and locals Steven D'Aprano <steve@pearwood.info> - 2014-02-27 04:47 +0000
Re: exec and locals Chris Angelico <rosuav@gmail.com> - 2014-02-27 16:05 +1100
Re: exec and locals Peter Otten <__peter__@web.de> - 2014-02-26 14:55 +0100
Re: exec and locals Alister <alister.ware@ntlworld.com> - 2014-02-26 14:00 +0000
Re: exec and locals Steven D'Aprano <steve@pearwood.info> - 2014-02-27 00:31 +0000
Re: exec and locals Alister <alister.ware@ntlworld.com> - 2014-02-27 09:59 +0000
csiph-web