String changing on the fly

Alex Martelli aleaxit at yahoo.com
Thu Oct 21 18:54:50 CEST 2004


Eli Daniel <elie at flashmail.com> wrote:
   ...
> Anyway when migerating from TCL, it's easy to teach somone to add at
> the end of the function call an additional parameter, "vars()" that
> telling him to sabtitue every parameter with '+ str(thevar)'. The
> reason is not that the later is harder to understand or write, it is
> simply less readable especialy when you write a large text with some
> variables as a parameter.

Sure, I agree.  string.Template in 2.4 chose $ for interpolation in part
exactly because it's popular in several other languages (perl, tcl,
bash).  Besides, +'ing a bunch of str(...) wouldn't be idiomatical
Python anyway; before string.Template, we tended to use more often the
C-derived concept of formatting --

'hello Mr %s' % surname

rather than

'hello Mr %(surname)s' % vars()


...

Alex



More information about the Python-list mailing list