equivelant of Java's toString() method? (not repr)
Alex Hunsley
lard at tardis.ed.ac.molar.uk
Tue Feb 1 08:13:14 EST 2005
Alex Hunsley wrote:
> Pretty simple seeming question, but can't find answer via google or docs...
>
> I am using urllib2 as follows:
>
> handle = urlopen(req, postdata) # and URL to return a handle on
> ...
> print handle.info()
>
> the print statement prints out the headers:
>
> Content-Type: text/html;charset=ISO-8859-1
> Content-Length: 2845
> Date: Tue, 01 Feb 2005 12:40:28 GMT
> Server: Apache Coyote/1.0
> Connection: close
>
> which is the string I want to use.
> However, if I write a function call using this:
>
> log(handle.info())
>
> I get this:
>
> TypeError: cannot concatenate 'str' and 'instance' objects
>
> (The log function expects a string)
> What is the magic incantation to get the string I want so I can pass it
> to my function?
> I've tried repr() but that isn't it (I suspected it wouldn't be).
> I suppose I'm looking for the equivelant of Java's toString() method...
>
> thanks!
> alex
Replying to meself...
D'oh! Just found the str() function which is just what I need!
log(str(handle.info())) works fine....
thx
alex
More information about the Python-list
mailing list