Replace high-bit characters in file.

Brian Quinlan brian at sweetapp.com
Sun Mar 31 16:17:54 EST 2002


Mikke wrote:

> I'm stuck!
> 
> I need a script that replaces national characters in a (dBase)file.
> 
> The original file is encoded in Latin-1 but I need it to be in CP850
> instead.

# This is not tested, of course
file_contents = open('dbasefile', 'rb').read()
file_contents = unicode(file_contents, 'latin-1').encode('cp850')
# file_contents is now a string containing the contents of the 
# file in cp850 format. You can write that string to a file, if you
# want. 
open('dbasefile.out', 'wb').write(file_contents)

Is that what you wanted?





More information about the Python-list mailing list