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: 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" To: danielk , "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> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 danielk wrote:=0D=0A> =0D=0A> The database I'm using stores information as = a 3-dimensional array=2E The delimiters between elements are=0D=0A> chr(252= ), chr(253) and chr(254)=2E So a record can look like this (example only us= es one of the delimiters for=0D=0A> simplicity):=0D=0A> =0D=0A> name + chr(= 254) + address + chr(254) + city + chr(254) + st + chr(254) + zip=0D=0A> = =0D=0A> The other delimiters can be embedded within each field=2E For examp= le, if there were multiple addresses for 'name'=0D=0A> then the 'address' f= ield would look like this:=0D=0A> =0D=0A> addr1 + chr(253) + addr2 + chr(25= 3) + addr3 + etc =2E=2E=2E=0D=0A> =0D=0A> I use Python to connect to the da= tabase using subprocess=2EPopen to run a server process=2E Python requests= =0D=0A> 'actions' like 'read' and 'write' to the server process, whereby th= e server process performs the actions=2E Some=0D=0A> actions require that t= he server send back information in the form of records that contain those d= elimiters=2E=0D=0A> =0D=0A> I have __str__ and __repr__ methods in the clas= ses but Python is choking on those characters=2E Surely, I could=0D=0A> con= vert those characters on the server before sending them to Python and that = is what I'm probably going to do,=0D=0A> so guess I've answered my own ques= tion=2E On Python 2, it just printed the 'extended' ASCII representation=2E= =0D=0A> =0D=0A> I guess the question I have is: How do you tell Python to u= se a specific encoding for 'print' statements when I=0D=0A> know there will= be characters outside of the ASCII range of 0-127?=0D=0A=0D=0AYou just nee= d to change the string to one that is not =0D=0Atrying to use the ASCII cod= ec when printing=2E =0D=0A=0D=0Aprint(chr(253)=2Edecode('latin1')) # change= latin1 to your =0D=0A # chosen encoding=2E= =0D=0A=FD=0D=0A=0D=0A=0D=0A~Ramit=0D=0A=0D=0A=0D=0AThis email is confidenti= al and subject to important disclaimers and=0D=0Aconditions including on of= fers for the purchase or sale of=0D=0Asecurities, accuracy and completeness= of information, viruses,=0D=0Aconfidentiality, legal privilege, and legal = entity disclaimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/dis= closures/email=2E