A simple file like
$ cat x.py
x = u'Gen\xe8ve'
print x
when run will give me:
$ python x.py
Genève
however, when run as a "command substitution" will give:
$ echo $(python x.py)
...
UnicodeEncodeError: 'ascii' codec...
I've tried with different terminal emulators (xterm, gnome-term) and the console on a ttyS. With bash and sh. With python2.4 and 2.7. I've tried setting the LC_ALL or LANG to some utf-8 locale before running python. I've checked the sys.getdefaultencoding(). And nothing helped.
The problem arises also when the script is called from another process (like java), but the above was the easiest way I found to replicate it.
I don't understand what's the difference between the two calls. Can anyone help?