Simple Question : files and URLLIB

Mark Carter cartermark46 at ukmail.com
Tue Oct 14 12:27:51 EDT 2003


> finA= urllib.urlopen('http://www.python.org/').read()
> 
> ... I haven't had time to look into this properly yet but I suspect
> finA is now a string not a file handle ?

Correct. If you do:
print type(finA)
you obtain the result:
<type 'str'>

If you do:
finA= urllib.urlopen('http://www.python.org/')
print type(finA)
then you obtain the result:
<type 'instance'>

Compare this with:
finA = open("blah", "w")
print type(finA)
which gives the result:
<type 'file'>

According to the docs on urlopen( url[, data[, proxies]]) :
"If all went well, a file-like object is returned."
So the answer would appear to be: "close, but no cigar".




More information about the Python-list mailing list