M
Michele Simionato
This is somewhat in between a bug report and a feature request.
I was using the new string.Template class and I have run into a
few issues that I traced back to the usage of the idiom
'%s' % val
in the 'convert' helper function in Template.substitute.
I do not understand why '%s' % val was used instead of just
str(val).
'%s' % val in unfortunate since it results in the following
surprising (for me) behavior:
'hello'
[not '("hello",)']
TypeError: not enough arguments for format string
[not '()']
Is this intended behavior? It is surprising since it is
different from what one would expect from old-fashioned string
interpolation
'()'
which is the behaviour I find most useful. Also, I do not like
that different expressions such as
T("$obj").substitute(obj=("hello",))
and T("$obj").substitute(obj="hello") give the same output
(this potentially hides type bugs).
So, take this as a bug report if the behavior is not intended and
as a feature request if the current behaviour is the intended
one
Michele Simionato
P.S. at the end, the problem is that string interpolation with
positional arguments is somewhat of a hack, but fixing this will
have to wait until Python 3000 ...
I was using the new string.Template class and I have run into a
few issues that I traced back to the usage of the idiom
'%s' % val
in the 'convert' helper function in Template.substitute.
I do not understand why '%s' % val was used instead of just
str(val).
'%s' % val in unfortunate since it results in the following
surprising (for me) behavior:
'hello'
[not '("hello",)']
TypeError: not enough arguments for format string
[not '()']
Is this intended behavior? It is surprising since it is
different from what one would expect from old-fashioned string
interpolation
'()'
which is the behaviour I find most useful. Also, I do not like
that different expressions such as
T("$obj").substitute(obj=("hello",))
and T("$obj").substitute(obj="hello") give the same output
(this potentially hides type bugs).
So, take this as a bug report if the behavior is not intended and
as a feature request if the current behaviour is the intended
one
Michele Simionato
P.S. at the end, the problem is that string interpolation with
positional arguments is somewhat of a hack, but fixing this will
have to wait until Python 3000 ...