string interpolation for python
Yingjie Lan
lanyjie at yahoo.com
Mon Apr 2 12:02:22 EDT 2012
>> In that case you should re-think the delimiters, so that you have
>> something
>> that can be nested. An example (example only, I'm not in love with it
> as
>> a final form):
Haven't really thought about that. Nesting is a big
issue if in the embedded expression, there is another
dynamic string expression. For example (the first
'%' immediately preceding the first quote denotes
the start of a dynamic string expression)::
>>> first_name, family_name = "Peter", "Johns"
>>> %"Hi $ first_name+%", $family_name$" $!"
'Hi Peter, Johns!'
However, nesting is really cluttering things up and
we should forbid it without loosing power:
The above example can be done without nesting:
>>> >>> %"Hi $ first_name$, $family_name$!"
'Hi Peter, Johns!'
Can you offer an example where nesting is
better or necessary?
Cheers,
Yingjie
More information about the Python-list
mailing list