Python: Converting File's Encoding

, , …,

How to convert a file encoding in Python?

# -*- coding: utf-8 -*-
# python

path='infile.html'
path2='outfile.html'

f= open(path, 'rb')
content= unicode(f.read(), 'gb18030')
f.close()
f= open(path2, 'wb')
f.write(content.encode('utf-8'))
f.close()

(thanks to Andrew Clover for help.)

blog comments powered by Disqus