Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9589 > unrolled thread
| Started by | Andrew Berg <bahamutzero8825@gmail.com> |
|---|---|
| First post | 2011-07-15 19:53 -0500 |
| Last post | 2011-07-15 19:53 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Print encoding problems in console Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-15 19:53 -0500
| From | Andrew Berg <bahamutzero8825@gmail.com> |
|---|---|
| Date | 2011-07-15 19:53 -0500 |
| Subject | Re: Print encoding problems in console |
| Message-ID | <mailman.1097.1310777621.1164.python-list@python.org> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
On 2011.07.15 07:02 PM, Pedro Abranches wrote:
> Now, if you're using your python script in some shell script you
> might have to store the output in some variable, like this:
>
> $ var=`python -c 'import sys; print sys.stdout.encoding; print
> u"\xe9"'`
>
> And what you get is:
>
> Traceback (most recent call last): File "<string>", line 1, in
> <module> UnicodeEncodeError: 'ascii' codec can't encode character
> u'\xe9' in position 0: ordinal not in range(128)
>
> So, python is not being able to detect the encoding of the output in
> a situation like that, in which the python script is called not
> directly but around ``.
FWIW, it works for me with Python 3:
$ x=$(/c/Python32/python -c print\(\'\\xe9\'\))
$ echo $x
é
I don't know how to get it to work with more than one command to Python;
bash always thinks the next commands are for it:
$ x=$(/c/Python32/python -c import sys; print\(sys.output.encoding\);
print\(\'\\xe9\'\))
File "<string>", line 1
import
^
SyntaxError: invalid syntax
bash: print(sys.output.encoding): command not found
bash: print('\xe9'): No such file or directory
This is using a very old MinGW bash, though.
- --
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAwAGBQJOIOEIAAoJEPiOA0Bgp4/LbSIIAJS9hVMTwQtV17pxWU5/IwRa
0X5v3W8mKZAyXTCSL5HmMQ07pPWRAkg5dEmnt+MTmFOVRjWg1yWIzeArmAc/MCmj
LiQcwp9ue6rY7Gt+gUqLFMQgVW9qs4zLLRAcThw9zMVLheOCrVoDc6miyLqcpb8+
RPjVuT9Bd5Vj67lIPOtZNTdB0hZGSwF5maerkot/95NBIuvP8UVBcub3dI6w1bJL
7dIW3NmjkeuWOdRch5s/X+gdPuoBNpfLfsFW3t7sdUscKKWaVjj0tOiNMHne42hD
XFuFauzmizaKpu16Zn9YJGPUhfvCn8QW+mcPFlBzv3g2oxuZMMssFykhU4Yb/7E=
=jVgu
-----END PGP SIGNATURE-----
Back to top | Article view | comp.lang.python
csiph-web