I have the contents of a file that contains French documentation.
I've iterated over it and now I want to write it out to a file.
I'm running into problems and I don't understand why--I don't get how the
encoding works.
My first attempt was just this:
< snipped code for classes, etc; fname is string, codecs module loaded.>
< self.contents is the French file's contents as a single string >
tFile = codecs.open(fna me,'w',encoding ='latin-1', errors='ignore' )
tFile.write(sel f.contents)
tFile.close()
ok, so that didn't work and I read some more and did this:
tFile.write(sel f.contents.enco de('latin-1'))
but that gives me the same error
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe9 in position 48:
ordinal not in range(128)
this is python2.4.1 (hpux)
sys.getdefaulte ncoding()
'ascii'
thanks,
--Tim Arnold
I've iterated over it and now I want to write it out to a file.
I'm running into problems and I don't understand why--I don't get how the
encoding works.
My first attempt was just this:
< snipped code for classes, etc; fname is string, codecs module loaded.>
< self.contents is the French file's contents as a single string >
tFile = codecs.open(fna me,'w',encoding ='latin-1', errors='ignore' )
tFile.write(sel f.contents)
tFile.close()
ok, so that didn't work and I read some more and did this:
tFile.write(sel f.contents.enco de('latin-1'))
but that gives me the same error
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe9 in position 48:
ordinal not in range(128)
this is python2.4.1 (hpux)
sys.getdefaulte ncoding()
'ascii'
thanks,
--Tim Arnold
Comment