[Tutor] more encoding strangeness

Eric Abrahamsen eric at ericabrahamsen.net
Tue Dec 23 08:10:58 CET 2008


Hi there,

I'm configuring a python command to be used by emacs to filter a  
buffer through python markdown, and noticed something strange. If I  
run this command in the terminal:

python -c "import sys,markdown; print  
markdown.markdown(sys.stdin.read().decode('utf-8'))" <  
markdown_source.md

The file (which is encoded as utf-8 and contains Chinese characters)  
is converted and output correctly to the terminal. But if I do this to  
write the output to a file:

python -c "import sys,markdown; print  
markdown.markdown(sys.stdin.read().decode('utf-8'))" <  
markdown_source.md > output.hml

I get a UnicodeEncodeError, 'ascii' codec can't encode character  
u'\u2014'. I'm not sure where exactly this is going wrong, as print  
and sys.stdout.write() and whatnot don't provide encoding parameters.  
What's the difference between this command writing to the terminal,  
and writing to the file?

Thanks,
Eric


More information about the Tutor mailing list