Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9589

Re: Print encoding problems in console

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bahamutzero8825@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'variable,': 0.07; 'python': 0.08; 'bash': 0.09; 'pgp': 0.09; 'skip:l 60': 0.09; 'subject:problems': 0.09; 'output': 0.11; 'syntax': 0.11; 'message-----': 0.12; 'received:209.85.214.174': 0.13; 'received:mail-iw0-f174.google.com': 0.13; 'wrote:': 0.15; ' -----begin': 0.16; '-----end': 0.16; '3.2.1': 0.16; 'bash,': 0.16; 'codec': 0.16; 'encode': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'ordinal': 0.16; 'python;': 0.16; 'skip:0 60': 0.16; 'thunderbird': 0.16; 'url:enigmail': 0.16; 'url:mozdev': 0.16; 'pm,': 0.16; 'this:': 0.16; 'comment:': 0.19; 'command': 0.19; '(most': 0.21; 'detect': 0.22; 'header:In-Reply-To:1': 0.22; 'though.': 0.23; 'invalid': 0.25; 'traceback': 0.25; 'windows': 0.26; 'received:209.85.214': 0.28; 'character': 0.28; 'import': 0.29; 'script': 0.29; 'shell': 0.29; 'id:': 0.29; 'print': 0.32; 'signed': 0.32; 'message-id:@gmail.com': 0.32; 'to:addr:python- list': 0.34; 'header:User-Agent:1': 0.34; "can't": 0.34; 'that,': 0.35; 'last):': 0.35; 'file': 0.36; 'some': 0.37; 'but': 0.37; 'using': 0.37; 'received:192': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'received:192.168.1': 0.39; 'version:': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'received:209': 0.40; 'called': 0.40; 'your': 0.60; '5.0': 0.84; 'bash:': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=M6RAIEo+4tXRlInEQgd5oeY4lipHJwkCbPPwdQ65uP0=; b=seo7pNLQ4g1zYnTGnAvItlvzNTlDAh2U7cl5WI8QTcdKUGJu/wvN/JcDc1f0kADs1N YkXogEeZVjH5G9HISpaFd5ZozrXP3x606DLKT31sYniVov2UmEYNs+GKNdjuJ5g8is8n tYA5M+7QRcF4dkX0Tz/3ABxO2Fz7HFG0aE5ys=
Date Fri, 15 Jul 2011 19:53:28 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version 1.0
To "comp.lang.python" <python-list@python.org>
Subject Re: Print encoding problems in console
References <CAHJDjt-ze0oox1XwMwOrGs=12LwqJ8nSYZosx_CN=ap4JK7x0Q@mail.gmail.com>
In-Reply-To <CAHJDjt-ze0oox1XwMwOrGs=12LwqJ8nSYZosx_CN=ap4JK7x0Q@mail.gmail.com>
X-Enigmail-Version 1.2
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1097.1310777621.1164.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310777621 news.xs4all.nl 23927 [2001:888:2000:d::a6]:52716
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9589

Show key headers only | View raw


-----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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Print encoding problems in console Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-15 19:53 -0500

csiph-web