Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'attribute': 0.05; 'ascii': 0.07; 'completeness': 0.07; 'performs': 0.07; 'python': 0.09; 'array.': 0.09; 'encoding.': 0.09; 'friday,': 0.09; 'subject:characters': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'do,': 0.15; 'encoding': 0.15; "'address'": 0.16; 'codec': 0.16; 'delimiters': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'printing.': 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; 'trying': 0.21; 'import': 0.21; 'elements': 0.23; 'this:': 0.23; "i've": 0.23; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'cc:addr:gmail.com': 0.27; 'embedded': 0.27; 'guess': 0.27; 'question': 0.27; 'accuracy': 0.27; 'run': 0.28; 'record': 0.28; 'statements': 0.29; 'convert': 0.29; 'probably': 0.29; "i'm": 0.29; 'classes': 0.30; 'file': 0.32; 'addresses': 0.32; 'could': 0.32; 'traceback': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'server': 0.35; 'process,': 0.35; 'stores': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'actions': 0.36; 'characters': 0.36; 'uses': 0.37; 'skip:3 10': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; '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; 'whereby': 0.91 Newsgroups: comp.lang.python Date: Fri, 9 Nov 2012 13:46:42 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.78.40.138; posting-account=S-UcDQoAAACh3mXdFBHQR00lNytDt6nm References: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> <99d5bd83-35ab-4801-b953-391c497c35bf@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 108.78.40.138 MIME-Version: 1.0 Subject: Re: Printing characters outside of the ASCII range From: danielk To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "python-list@python.org" , danielk 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: , Message-ID: Lines: 99 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352497611 news.xs4all.nl 6923 [2001:888:2000:d::a6]:43395 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33057 On Friday, November 9, 2012 4:34:19 PM UTC-5, Prasad, Ramit wrote: > danielk wrote: >=20 > >=20 >=20 > > The database I'm using stores information as a 3-dimensional array. The= delimiters between elements are >=20 > > chr(252), chr(253) and chr(254). So a record can look like this (exampl= e only uses one of the delimiters for >=20 > > simplicity): >=20 > >=20 >=20 > > name + chr(254) + address + chr(254) + city + chr(254) + st + chr(254) = + zip >=20 > >=20 >=20 > > The other delimiters can be embedded within each field. For example, if= there were multiple addresses for 'name' >=20 > > then the 'address' field would look like this: >=20 > >=20 >=20 > > addr1 + chr(253) + addr2 + chr(253) + addr3 + etc ... >=20 > >=20 >=20 > > I use Python to connect to the database using subprocess.Popen to run a= server process. Python requests >=20 > > 'actions' like 'read' and 'write' to the server process, whereby the se= rver process performs the actions. Some >=20 > > actions require that the server send back information in the form of re= cords that contain those delimiters. >=20 > >=20 >=20 > > I have __str__ and __repr__ methods in the classes but Python is chokin= g on those characters. Surely, I could >=20 > > convert those characters on the server before sending them to Python an= d that is what I'm probably going to do, >=20 > > so guess I've answered my own question. On Python 2, it just printed th= e 'extended' ASCII representation. >=20 > >=20 >=20 > > I guess the question I have is: How do you tell Python to use a specifi= c encoding for 'print' statements when I >=20 > > know there will be characters outside of the ASCII range of 0-127? >=20 >=20 >=20 > You just need to change the string to one that is not=20 >=20 > trying to use the ASCII codec when printing.=20 >=20 >=20 >=20 > print(chr(253).decode('latin1')) # change latin1 to your=20 >=20 > # chosen encoding. >=20 > =FD >=20 >=20 >=20 >=20 >=20 > ~Ramit >=20 >=20 >=20 >=20 >=20 > This email is confidential and subject to important disclaimers and >=20 > conditions including on offers for the purchase or sale of >=20 > securities, accuracy and completeness of information, viruses, >=20 > confidentiality, legal privilege, and legal entity disclaimers, >=20 > available at http://www.jpmorgan.com/pages/disclosures/email. D:\home\python>pytest.py Traceback (most recent call last): File "D:\home\python\pytest.py", line 1, in print(chr(253).decode('latin1')) AttributeError: 'str' object has no attribute 'decode' Do I need to import something?