Simple Question : files and URLLIB
Richard Shea
richardshea at fastmail.fm
Tue Oct 14 06:03:05 EDT 2003
Hi - I'm new to Python. I've been trying to use URLLIB and the 'tidy'
function (part of the mx.tidy package). There's one thing I'm having
real difficulties understanding. When I did this ...
finA= urllib.urlopen('http://www.python.org/')
foutA=open('C:\\testout.html','w')
tidy(finA,foutA,None)
I get ...
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "mx\Tidy\Tidy.py", line 38, in tidy
return mxTidy.tidy(input, output, errors, kws)
TypeError: inputstream must be a file object or string
... what I don't understand is surely the result of a urllib is a file
object ? Isn't it ? To quote the manual at :
http://www.python.org/doc/current/lib/module-urllib.html
"If all went well, a file-like object is returned". I can make the
tidy function happy but changing the code to read ...
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 ?
Anyway if anyone can throw light on this I would be grateful.
thanks
richard.shea.
More information about the Python-list
mailing list