[Python-Dev] PEP_215_ (string interpolation) alternative EvalDict
Jason Orendorff
jason@jorendorff.com
Mon, 14 Jan 2002 22:16:11 -0600
> On Mon, 14 Jan 2002, Skip Montanaro wrote:
> > $'BDFL = $sys.copyright.split()[4].upper()'
> > ---> ('BDFL = ' + str(sys.copyright.split()[4].upper()))
> >
> > How to you know when to stop gobbling after seeing a dollar sign in the
> > string?
>
> Parse using the "NAME trailer*" production in Grammar/Grammar.
Except that whitespace is significant, at least in the sample
implementation:
>>> i = Itpl.itpl
>>> x=4
>>> y=3
>>> i("This is x: $x. This is y: $y.") # doesn't grab (x.This)
'This is x: 4. This is y: 3.'
>>> i("This is x: $x.This is y: $y.") # does grab (x.This)
AttributeError: 'int' object has no attribute 'This'
This doesn't seem to be mentioned in the PEP.
## Jason Orendorff http://www.jorendorff.com/