string.join question (was Re: urllib question)

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Sun Jun 18 05:40:21 EDT 2000


paul at fizzylab.com wrote in comp.lang.python:
> Nothing. That's the problem. The item I want to append to the first never gets
> evaluated/appended. I get the first item -- the host name -- and I make a valid
> request for the root of the webserver, not what I want. It's as if I requested
> 'http://www.site.com/' rather than 'http://www.site.com/thispage.html'  which is
> not what I want.
> 
> See the code I submitted initially . . . . the first example works, the second
> does not.
> 
> #!/usr/bin/python
> import string, urllib
> 
> u = urllib.urlopen(string.join(["http://cnn.com/","index.html"]))
> print u.read()
> u =
> urllib.urlopen(string.join(["http://some.host.com/","monstrousQueryString?withParameters"]))
> 
> print u.read()

String.join() puts spaces in between the strings by default. The first one
works because it gets "http://cnn.com", which is incidentally the same page
as "http://cnn.com/index.html".

Maybe just use + instead of string.join? :)

urllib.urlopen("http://some.host.com/"+"monstrousetc") 


-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
"Early to rise, early to bed, makes a man healthy, wealthy and dead." -- TP



More information about the Python-list mailing list