[Python-Dev] Re: Re: Re: Re: Update PEP 292 (original) (raw)

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: fooandthisisfoo.bar:foo and this is foo.bar: fooandthisisfoo.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,andsomeobjectparams:var, and some object params: var,andsomeobjectparams:self.x, self.y,self.y, 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: varandattr:var and attr: varandattr: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