From python to LaTeX in emacs on windows

Brian Elmegaard brian at rk-speed-rugby.dk
Tue Aug 31 04:34:08 EDT 2004


Benjamin Niemann <b.niemann at betternet.de> writes:

Thank for the help. I solved the problem by specifying the cp1252
encoding for the python file by a magic comment and for the input data file. 

> When you read the filecontents in python, you'll have the "raw" byte
> sequence, in this case it is the UTF-8 encoding of unicode text. But
> you probably want a unicode string. Use "text = unicode(data,
> 'utf-8')" where "data" is the filecontent you read. After processing
> you probably want to write it back to a file. Before you do this, you
> will have to convert the unicode string back to a byte sequence. Use
> "data = text.encode('utf')".
> 

This worked, but when I try to print text I get:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-10: ordinal not in range(128)
Why is that?

> Handling character encodings correctly *is* difficult. 

What makes it difficult? The OS, the editor, python, latex?

-- 
Brian (remove the sport for mail)
http://www.et.dtu.dk/staff/be



More information about the Python-list mailing list