urllib2 (py2.6) vs urllib.request (py3)

mattia gervaz at gmail.com
Tue Mar 17 10:59:10 CET 2009


Hi all, can you tell me why the module urllib.request (py3) add extra 
characters (b'fef\r\n and \r\n0\r\n\r\n') in a simple example like the 
following and urllib2 (py2.6) correctly not?

py2.6
>>> import urllib2
>>> f = urllib2.urlopen("http://www.google.com").read()
>>> fd = open("google26.html", "w")
>>> fd.write(f)
>>> fd.close()

py3
>>> import urllib.request
>>> f = urllib.request.urlopen("http://www.google.com").read()
>>> with open("google30.html", "w") as fd:
...     print(f, file=fd)
...
>>>

Opening the two html pages with ff I've got different results (the extra 
characters mentioned earlier), why?



More information about the Python-list mailing list