How do I force Latin-1 (which I guess means iso-8859-1?) file output in Python?
Here's my code at the moment. It works, but trying to import the resulting output file into a Latin-1 MySQL table produces weird encoding errors.
outputFile = file( "textbase.tab", "w" )
for k, v in textData.iteritems():
complete_line = k + '~~~~~' + v + '~~~~~' + " ENDOFTHELINE"
outputFile.write(complete_line)
outputFile.write( "\n" )
outputFile.close()
The resulting output file seems to be saved in "Western (Mac OS Roman)", but if I then save it in Latin-1, I still get strange encoding problems. How can I make sure that the strings used, and the file itself, are all encoded in Latin-1 as soon as they are generated?
The original strings (in the textData
dictionary) have been parsed in from an RTF file - I don't know if that makes a difference.
I'm a bit new to Python and to encoding generally, so apologies if this is a dumb question. I have tried looking at the docs but haven't got very far.
I'm using Python 2.6.1.