[Tutor] WHY IT DI DIS?

Michael P. Reilly arcege@speakeasy.net
Thu, 27 Dec 2001 18:40:17 -0500


On Thu, Dec 27, 2001 at 04:53:25PM -0500, Kirk Bailey wrote:
> OK, WHY DOES IT DO THIS?
> 
> 
> ns# ./TLwebmgr.py
>   File "./TLwebmgr.py", line 35
>     print "<a href=" + \" + webpath + "cgi-bin/commander.py?list=" + x +
> \" + '>' + x + "</a> ", descriptor(x) + '<P>'
>                                                                                                                     
> ^
> SyntaxError: invalid token
> 

The   + \" +   expression is incorrect.  Quoting a double quote
only works withing a string.  In a more simple form you can have:
  print "<a href=\"" + webpath + "cgi-bin/commander.py?list=" + x + \
    "\">" + x + "</a> ", descriptor(x) + "<P>"

Or with string formats and single quotes,
  print '<a href="%scgi-bin/commander.py?list=%s">%s</a> %s<P>' % \
    ( webpath, x, x, descriptor(x) )

The only place where you may want to be more distinguishing is at the
'%scgi' part.  But then for that one URL concatenation, I'd be using
urlparse.urljoin myself. :)

  -Arcege