Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'ascii': 0.07; 'performs': 0.07; 'python': 0.09; 'array.': 0.09; 'delimiter': 0.09; 'encode': 0.09; 'friday,': 0.09; 'processing,': 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; 'directly?': 0.16; 'string': 0.17; 'wrote:': 0.17; 'bytes': 0.17; 'requests': 0.18; 'app': 0.19; 'question.': 0.20; 'skip:" 30': 0.20; 'elements': 0.23; 'errors': 0.23; 'originally': 0.23; 'this:': 0.23; "i've": 0.23; '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; 'cc:2**2': 0.27; 'converting': 0.27; 'fine': 0.28; 'run': 0.28; 'record': 0.28; 'statements': 0.29; 'unlikely': 0.29; 'character': 0.29; 'convert': 0.29; 'probably': 0.29; "i'm": 0.29; 'classes': 0.30; 'error': 0.30; 'file': 0.32; 'addresses': 0.32; 'could': 0.32; 'traceback': 0.33; 'handle': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'server': 0.35; 'process,': 0.35; 'saved': 0.35; 'stores': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'actions': 0.36; 'cc:no real name:2**1': 0.36; 'characters': 0.36; 'does': 0.37; 'uses': 0.37; 'skip:3 10': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'some': 0.38; 'things': 0.38; 'application': 0.40; 'your': 0.60; 'address': 0.60; 'range': 0.60; 'skip:u 10': 0.60; 'further': 0.61; 'real': 0.61; 'kind': 0.61; 'back': 0.62; 'between': 0.63; 'information': 0.63; 'within': 0.64; 'fun': 0.64; 'results': 0.65; 'skip:c 50': 0.66; 'records': 0.68; 'city': 0.69; 'received:209.85.213.184': 0.91; 'whereby': 0.91; 'angel': 0.93 Newsgroups: comp.lang.python Date: Fri, 9 Nov 2012 13:17:39 -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> 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, d@davea.name, 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: 104 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352495868 news.xs4all.nl 6929 [2001:888:2000:d::a6]:51506 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33052 On Friday, November 9, 2012 12:48:05 PM UTC-5, Dave Angel wrote: > On 11/09/2012 12:17 PM, danielk wrote: >=20 > > I'm converting an application to Python 3. The app works fine on Python= 2. >=20 > > >=20 > > Simply put, this simple one-liner: >=20 > > >=20 > > print(chr(254)) >=20 > > >=20 > > errors out with: >=20 > > >=20 > > Traceback (most recent call last): >=20 > > File "D:\home\python\tst.py", line 1, in >=20 > > print(chr(254)) >=20 > > File "C:\Python33\lib\encodings\cp437.py", line 19, in encode >=20 > > return codecs.charmap_encode(input,self.errors,encoding_map)[0] >=20 > > UnicodeEncodeError: 'charmap' codec can't encode character '\xfe' in po= sition 0: character maps to >=20 > > >=20 > > I'm using this character as a delimiter in my application. >=20 > > >=20 > > What do I have to do to convert this string so that it does not error o= ut? >=20 >=20 >=20 > What character do you want? What characters do your console handle >=20 > directly? What does a "delimiter" mean for your particular console? >=20 >=20 >=20 > Or are you just printing it for the fun of it, and the real purpose is >=20 > for further processing, which will not go to the console? >=20 >=20 >=20 > What kind of things will it be separating? (strings, bytes ?) Clearly >=20 > you originally picked it as something unlikely to occur in those elements= . >=20 >=20 >=20 > When those things are combined with a separator between, how are the >=20 > results going to be used? Saved to a file? Printed to console? What? >=20 >=20 >=20 > --=20 >=20 >=20 >=20 > DaveA The database I'm using stores information as a 3-dimensional array. The del= imiters between elements are chr(252), chr(253) and chr(254). So a record c= an look like this (example only uses one of the delimiters for simplicity): name + chr(254) + address + chr(254) + city + chr(254) + st + chr(254) + zi= p The other delimiters can be embedded within each field. For example, if the= re were multiple addresses for 'name' then the 'address' field would look l= ike this: addr1 + chr(253) + addr2 + chr(253) + addr3 + etc ... I use Python to connect to the database using subprocess.Popen to run a ser= ver process. Python requests 'actions' like 'read' and 'write' to the serve= r process, whereby the server process performs the actions. Some actions re= quire that the server send back information in the form of records that con= tain 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 b= efore 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 'exte= nded' ASCII representation. I guess the question I have is: How do you tell Python to use a specific en= coding for 'print' statements when I know there will be characters outside = of the ASCII range of 0-127?