[Python-Dev] Re: Re: Update PEP 292 (original) (raw)
Fernando Perez fperez528 at yahoo.com
Wed Aug 11 16:54:27 CEST 2004
- Previous message: [Python-Dev] Re: Update PEP 292
- Next message: [Python-Dev] Re: Re: Update PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Barry Warsaw wrote:
On Wed, 2004-08-11 at 08:06, Fernando Perez wrote:
If I understood things correctly, this proposal will not allow the evaluation of any kind of expression, including attributes. With the existing interpolation system, the following happens:
In [2]: print 'sys.platform is: %(sys.platform)s' % locals() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) ? KeyError: sys.platform You don't mean the 'existing' interpolation system, because this obviously doesn't work in Python today, although with a fancy enough implementation of 'locals()', it could. That actually doesn't change much with PEP 292. I specifically designed it so that you could subclass from template, so as to accept the extended placeholder syntax (i.e. dots), and then implement a mapping-like class to do the lookups in any namespace you want. In fact, my earlier implementation contained such a class, but it was deemed too complex to win the name 'simpler' so it was left out of the library. It's a trivial amount of code and my own personal use case has a need for such a feature.
I guess my post wasn't worded too clearly. I did mean existing, in the sense that the error above occurs with current python (it's cut-and-paste from python 2.2). My point was precisely to illustrate this failure with a simple example, to then ask whether the new scheme could be made, as shipped, to accept this kind of expansion:
print template('sys.platform is: $sys.platform') % locals()
It may be trivial to extend pep-292 for this, but not having to do it in every small utility you write/ship would be very useful, IMHO. If there are no technical reasons to prevent it, is the 'too complex' argument really that strong (especially since you state it's a trivial amount of code)?
I hope this clarifies better my question.
Regards,
f
- Previous message: [Python-Dev] Re: Update PEP 292
- Next message: [Python-Dev] Re: Re: Update PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]