[Python-Dev] Re: Re: Re: Re: Update PEP 292

Fernando Perez fperez528 at yahoo.com
Mon Aug 23 01:35:36 CEST 2004


Barry Warsaw wrote:

> On Wed, 2004-08-18 at 14:07, Fernando Perez wrote:
> 
>> I'd like to argue that this form may be the most useful for common tasks, so
>> you can mix and match "this is foo: $foo and this is foo.bar: $foo.bar"
>> without having to worry too much about which template class you are using.
> 
> It might be, but using attribute lookup syntax can be problematic.  I
> can only relate my experiences with Mailman, where I've been using
> something similar for several years, albeit with traditional
> %-placeholders.

[...]

I trust your judgment an openness on this, and indeed prudence has served python
well in the past.  I'd just like this to be available so I could handle a very
common case like:

'a local var: $var, and some object params: $self.x, $self.y, $self.z'

This can't easily be solved with the current syntax of %()s, since the
namespaces for self (self.__dict__) and locals are different, and there's no
attribute lookup.

How about making template objects callable (or providing an eval() method)?  It
would allow the following:

tpl = template('a var $foo')

print tpl -> evaluates under the current rules, by calling __str__

but:

tpl2 = template('local: $var and attr: $self.x')

print tpl2()  # or tpl2.eval(), or whatever other name

where the call has _optional_ local/global arguments?  This could satisfy the
common case while allowing evaluation in restricted contexts:

print tpl2(my_locals,my_globals)

Anyway, just some thoughts on this...

Best regards,

Fernando



More information about the Python-Dev mailing list