Py3 - converting bytes to ascii

Casey Caseyweb at gmail.com
Thu Jan 15 16:53:25 CET 2009


On Jan 15, 9:54 am, "Anjanesh Lekshminarayanan" <m... at anjanesh.net>
wrote:
> Using Python 3.0
>
> So how do I to convert res.read() to ascii on opening the file in
> ascii mode f = open('file.txt', 'w')?
>

I think this is what you are looking for:

res = urllib.request.urlopen(url)
f = open('file.txt', 'w')
f.write(res.read().decode('ascii'))



More information about the Python-list mailing list