Py3 - converting bytes to ascii

Anjanesh Lekshminarayanan mail at anjanesh.net
Thu Jan 15 09:54:59 EST 2009


Using Python 3.0

res = urllib.request.urlopen(url)
f = open('file.txt', 'wb') # Since res.read() returns bytes
f.write(res.read())

But newline and return feeds are stored as b14, 58a as text in the text file.

So how do I to convert res.read() to ascii on opening the file in
ascii mode f = open('file.txt', 'w')?

Thanks



More information about the Python-list mailing list