forced spaces when inserting a variable between strings
Stephen Illingworth
me at privacy.net
Tue Jan 17 11:08:54 EST 2006
mjteigen wrote:
> My goal is print out '<img src="5.jpg">'. However, when I view the
> source on the generated html page, I see this:
>
> <img src= 5 .jpg>
>
> In other words, that "5" has a space tacked on either side of it, and
> of course a browser can't find the file. Is there a way I can avoid the
> tacking of spaces on either side of a variable inserted between two
> strings?
Yes, use placeholders. In your example,
print "<img src=\"%d.jpg\">" % (number,)
http://www.python.org/dev/doc/devel/lib/typesseq-strings.html
http://diveintopython.org/native_data_types/formatting_strings.html
More information about the Python-list
mailing list