Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83754
| Return-Path | <rosuav@gmail.com> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'anyway.': 0.05; 'modify': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '.py': 0.16; 'be:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function?': 0.16; 'subject:skip:e 10': 0.16; 'xslt,': 0.16; 'flexibility': 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'skip:p 40': 0.19; 'thu,': 0.19; 'solution.': 0.20; 'code,': 0.22; 'input': 0.22; 'import': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'propose': 0.24; 'cc:2**0': 0.24; "i've": 0.25; '15,': 0.26; 'compiled': 0.26; 'this:': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'code': 0.31; 'anyone': 0.31; 'file': 0.32; 'run': 0.32; 'actual': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'disk': 0.36; 'executing': 0.36; 'yield': 0.36; 'done': 0.36; 'possible': 0.36; 'feedback': 0.38; 'thank': 0.38; 'fact': 0.38; 'rather': 0.38; 'sure': 0.39; 'how': 0.40; 'read': 0.60; 'entire': 0.61; 'different': 0.65; 'worth': 0.66; 'potentially': 0.81; '*and*': 0.84; '2015': 0.84; 'clearer': 0.84; 'quicker': 0.84; 'xslt': 0.84; 'gender': 0.91; 'to:none': 0.92; 'directly.': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Er6x4JnDeYYyUTJo9GPZ4yJB4O0zcTIaaY2h33gpnw0=; b=eCYiBaDBo8QppjzVo7AxTR2WJv3BaYn+9wZRjSat4krvBoxTKGo4Qd07+zx3LRuhEo iHf809U5XICTgY/aIqWPRfTUazDinsOVIYdbzjmrzGWj5CACQAgQrdRs99DW/o1zoYkf S2NaEPUkxXNHyQZRHruJriMXpC3wKkdW9piibXIzHR4i4uAVGwxgC9BDsOnyVjBp+aWk 09vvW1rqbgjmvvlfpgM+OChVYdkszSV/O6iiwFuBCfVOK+Wpiy1WYsHSc691BDHT28/9 zbSwbu+tbPUoxVidTqLsx3aPDEIGzhKIj6HMWXc01rhZNK147+aX4tpSPgxVVY5yI98n JQ3Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.95.12 with SMTP id d12mr4567132icn.12.1421243028140; Wed, 14 Jan 2015 05:43:48 -0800 (PST) |
| In-Reply-To | <CABUUr0wj5-WKmwFb7RgoFzLOtMjEgQqm2nQDPtjLJGPhXiVPvQ@mail.gmail.com> |
| References | <mailman.17684.1421168544.18130.python-list@python.org> <54b592ac$0$12995$c3e8da3$5496439d@news.astraweb.com> <CABUUr0yYBM=EJpcZXX2mJ0pz13Tum8px3Z8y3EZcr0VEo6Bfpw@mail.gmail.com> <CAPTjJmoTyMuLaY-z06Bfiw-SSratCkRMktQ1mQ2UhG=7jm6vZg@mail.gmail.com> <CABUUr0wj5-WKmwFb7RgoFzLOtMjEgQqm2nQDPtjLJGPhXiVPvQ@mail.gmail.com> |
| Date | Thu, 15 Jan 2015 00:43:48 +1100 |
| Subject | Re: Performance in exec environnements |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.17720.1421243030.18130.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1421243030 news.xs4all.nl 2918 [2001:888:2000:d::a6]:53830 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:83754 |
Show key headers only | View raw
On Thu, Jan 15, 2015 at 12:38 AM, Jean-Baptiste Braun
<jbaptiste.braun@gmail.com> wrote:
> 2015-01-14 12:14 GMT+01:00 Chris Angelico <rosuav@gmail.com>:
>>
>> Would it be possible to do a one-off transformation of the entire XSLT
>> file into a Python module with a single function in it, and then every
>> time you need that XSLT, you import that module and call the function?
>> That would potentially be a lot quicker than exec(), *and* would be
>> much clearer - there'd be an actual file on the disk with your
>> generated Python code, and anyone could read it and understand what
>> it's doing.
>
> I've done some tests executing compiled generated python and it doesn't seem
> to be worth over processing xslt directly. What you propose could be a
> solution. In fact I'm not sure yet how it will be designed.
>
> Thank you for feedback anyway.
I don't know how often you need to re-process the same XSLT file, but
if you often run the same file (eg with different input data), then
you could create a .py file and import it, and then call it. Something
like this:
# Python code generated from some_file.xslt - DO NOT MODIFY
def process(gender):
print('<title>')
if gender == 'M':
print('Mr')
else:
print('Mrs')
print('</title>')
And then you'd use it thus:
import some_file
some_file.process(gender='M')
Although rather than using print(), it might be better to use yield:
# Python code generated from some_file.xslt - DO NOT MODIFY
def process(gender):
yield '<title>'
if gender == 'M':
yield 'Mr'
else:
yield 'Mrs'
yield'</title>'
And then usage would be:
import some_file
print("\n".join(some_file.process(gender='M')))
which gives you the flexibility of sending it somewhere other than
stdout, without monkey-patching the print function to do something
else.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Performance in exec environnements Jean-Baptiste Braun <jbaptiste.braun@gmail.com> - 2015-01-13 18:02 +0100
Re: Performance in exec environnements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-14 08:48 +1100
Re: Performance in exec environnements Jean-Baptiste Braun <jbaptiste.braun@gmail.com> - 2015-01-14 10:02 +0100
Re: Performance in exec environnements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-15 12:51 +1100
Re: Performance in exec environnements Chris Angelico <rosuav@gmail.com> - 2015-01-14 22:14 +1100
Re: Performance in exec environnements Jean-Baptiste Braun <jbaptiste.braun@gmail.com> - 2015-01-14 14:38 +0100
Re: Performance in exec environnements Chris Angelico <rosuav@gmail.com> - 2015-01-15 00:43 +1100
Re: Performance in exec environnements Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-14 10:11 -0700
csiph-web