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


Groups > comp.lang.python > #33054

RE: Printing characters outside of the ASCII range

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'ascii': 0.07; 'completeness': 0.07; 'performs': 0.07; 'python': 0.09; 'array.': 0.09; 'encoding.': 0.09; 'received:155': 0.09; 'subject:characters': 0.09; 'do,': 0.15; 'encoding': 0.15; "'address'": 0.16; 'codec': 0.16; 'delimiters': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'printing.': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'string': 0.17; 'wrote:': 0.17; 'requests': 0.18; 'skip:p 30': 0.20; 'question.': 0.20; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'elements': 0.23; 'this:': 0.23; 'to:2**1': 0.23; "i've": 0.23; 'received:169.254': 0.24; 'header:In-Reply- To:1': 0.25; 'embedded': 0.27; 'guess': 0.27; 'question': 0.27; 'accuracy': 0.27; 'run': 0.28; 'record': 0.28; 'statements': 0.29; 'convert': 0.29; 'received:169': 0.29; 'probably': 0.29; "i'm": 0.29; 'classes': 0.30; 'header:Received:8': 0.30; 'addresses': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'server': 0.35; 'process,': 0.35; 'stores': 0.35; 'there': 0.35; 'but': 0.36; 'actions': 0.36; 'characters': 0.36; 'uses': 0.37; 'skip:3 10': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'your': 0.60; 'address': 0.60; 'range': 0.60; 'back': 0.62; 'between': 0.63; 'information': 0.63; 'information,': 0.63; 'url:email': 0.63; 'within': 0.64; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'records': 0.68; 'city': 0.69; 'sale': 0.76; 'received:169.254.8': 0.84; 'whereby': 0.91
X-DKIM OpenDKIM Filter v2.1.3 sj3.jpmchase.com qA9LYAG0008438
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1352496850; bh=dIWgRgSBF7cgv6/MC/10iWEJgqtvq2jnNDZSAS6Fw6g=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=XXQXzEX9dDHZsCW2gFBVo7fXzd9Z7YZvowLPde7vCXYlfEglalR3n1vkQZMPpqFeC vyYNOj8sETqCg4WVaRFYwD1jhzxMAOKfR4/6UWGBhxhT8zzz19l0iGjZ3cdDWm6rvd Ojm7Ju6ABZb2FSaoglz84YOVNmO3cVttqJHG1qzo=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To danielk <danielkleinad@gmail.com>, "python-list@python.org" <python-list@python.org>
Subject RE: Printing characters outside of the ASCII range
Thread-Topic Printing characters outside of the ASCII range
Thread-Index AQHNvr+la2Nq3V20YEW0crMmLrulE5fiBIdA
Date Fri, 9 Nov 2012 21:34:01 +0000
References <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> <mailman.3508.1352483285.27098.python-list@python.org> <99d5bd83-35ab-4801-b953-391c497c35bf@googlegroups.com>
In-Reply-To <99d5bd83-35ab-4801-b953-391c497c35bf@googlegroups.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="iso-8859-1"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.3517.1352496859.27098.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352496859 news.xs4all.nl 6913 [2001:888:2000:d::a6]:36788
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33054

Show key headers only | View raw


danielk wrote:
> 
> The database I'm using stores information as a 3-dimensional array. The delimiters between elements are
> chr(252), chr(253) and chr(254). So a record can look like this (example only uses one of the delimiters for
> simplicity):
> 
> name + chr(254) + address + chr(254) + city + chr(254) + st + chr(254) + zip
> 
> The other delimiters can be embedded within each field. For example, if there were multiple addresses for 'name'
> then the 'address' field would look like this:
> 
> addr1 + chr(253) + addr2 + chr(253) + addr3 + etc ...
> 
> I use Python to connect to the database using subprocess.Popen to run a server process. Python requests
> 'actions' like 'read' and 'write' to the server process, whereby the server process performs the actions. Some
> actions require that the server send back information in the form of records that contain those delimiters.
> 
> I have __str__ and __repr__ methods in the classes but Python is choking on those characters. Surely, I could
> convert those characters on the server before sending them to Python and that is what I'm probably going to do,
> so guess I've answered my own question. On Python 2, it just printed the 'extended' ASCII representation.
> 
> I guess the question I have is: How do you tell Python to use a specific encoding for 'print' statements when I
> know there will be characters outside of the ASCII range of 0-127?

You just need to change the string to one that is not 
trying to use the ASCII codec when printing. 

print(chr(253).decode('latin1')) # change latin1 to your 
                                 # chosen encoding.
ý


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 09:17 -0800
  Re: Printing characters outside of the ASCII range Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-09 10:34 -0700
  Re: Printing characters outside of the ASCII range Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-09 11:39 -0600
  Re: Printing characters outside of the ASCII range Dave Angel <d@davea.name> - 2012-11-09 12:47 -0500
    Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:17 -0800
      RE: Printing characters outside of the ASCII range "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-09 21:34 +0000
        Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:46 -0800
          Re: Printing characters outside of the ASCII range Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-09 15:10 -0700
            Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-11 05:42 -0800
              Re: Printing characters outside of the ASCII range Lele Gaifax <lele@metapensiero.it> - 2012-11-11 18:09 +0100
            Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-11 05:42 -0800
        Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:46 -0800
      Re: Printing characters outside of the ASCII range Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-09 15:39 -0600
    Re: Printing characters outside of the ASCII range danielk <danielkleinad@gmail.com> - 2012-11-09 13:17 -0800
  Re: Printing characters outside of the ASCII range wxjmfauth@gmail.com - 2012-11-10 02:09 -0800
  Re: Printing characters outside of the ASCII range Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-11-11 15:40 +0100

csiph-web