Skip to content

Instantly share code, notes, and snippets.

@japsu
Created March 21, 2012 10:47
Show Gist options
  • Save japsu/2146116 to your computer and use it in GitHub Desktop.
Save japsu/2146116 to your computer and use it in GitHub Desktop.
Python stdout weirdness
japsu@eris ~ $ cat foo.py
#!/usr/bin/env python
# encoding: utf-8
import sys
sys.stdout.write(u"åöä\n")
japsu@eris ~ $ python foo.py
åöä
japsu@eris ~ $ python foo.py | cat
Traceback (most recent call last):
File "foo.py", line 5, in <module>
sys.stdout.write(u"åöä\n")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment