forced spaces when inserting a variable between strings

mjteigen mjteigen at
Tue Jan 17 10:56:16 EST 2006

I'm very new at Python, but have been trying it in conjunction with
CGI. I've encountered a problem that I'm pretty sure is a trivial one,
but I don't know enough Python to work it out. Here's an example.
Imagine that I have a file named "5.jpg" in the same directory as this
Python script:

   print "content-type: text/html\n"
   number = 5
   print "<img src=",number,".jpg>"

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

TIA :-)
m j teigen

More information about the Python-list mailing list