Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'problem?': 0.07; 'subject:characters': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'def': 0.12; 'wrote': 0.14; 'encodings,': 0.16; 'repr.': 0.16; 'subject:non': 0.16; 'true:': 0.16; 'later': 0.20; 'print': 0.22; 'this:': 0.26; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.30; 'prints': 0.31; 'text': 0.33; 'skip:b 30': 0.33; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'hi,': 0.36; 'handle': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'break': 0.61; 'first': 0.61; 'therefore,': 0.64; 'different': 0.65; 'from:charset:iso-8859-9': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=nYx7Maljf+2YaGYq8zLB+wTfdylKQXl30p5V9WyNaxc=; b=GuCSMBSgIuCUdDENhWIpBF3y0Cmf++Vwbx/m/RXnDJJZMQSvUp5c36ssaMCy9Y8Kw7 B21RC7U1ydsX3ERE187jq29WMNcJyP3x/G4WjTdzXhEsLNLXN/e+HzW1IbKlg5/5lCab BUu+53cfIzeMkN12RPQ9umcXCQjTwssbrWsLUFkJDDRnwIJ2QMaMUeGMOx9dwXETqYBF i2CXLlQWf23GOY8OjuFdpd0Atw68TzfnNmoR4d0D++xnWny1Go8PPETNFU+zPC0GAd9h 6DEYc9X79vxNFJzLytSK9mfrkidkHXrKhe72wrg25ozr29mJcfcVYMpPGj/YaWc9eL7Q Xx0g== MIME-Version: 1.0 X-Received: by 10.204.170.73 with SMTP id c9mr309790bkz.67.1383231576504; Thu, 31 Oct 2013 07:59:36 -0700 (PDT) Date: Thu, 31 Oct 2013 16:59:36 +0200 Subject: tuple __repr__ non-ascii characters From: =?ISO-8859-9?Q?Ya=FEar_Arabac=FD?= To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-9 Content-Transfer-Encoding: quoted-printable 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383231583 news.xs4all.nl 15916 [2001:888:2000:d::a6]:54477 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58181 Hi, while this: a =3D "ya=FEar" print a prints "ya=FEar" this: a =3D ("ya=FEar",) print a prints ('ya\xfear',) At first I tried decoding repr(a) with different encodings, but later I realised there is actually 4 charaters \, x, f and e in return value of repr. Therefore, I wrote this: def byte_replacement(bstring): return chr(int(bstring[2:],16)) def prettyprint(obj): text =3D repr(obj) while True: try: start =3D text.index("\\x") text =3D text[:start] + byte_replacement(text[start:start+4]) + text[start+4:] except ValueError: break print text Is there a better way to handle this problem? --=20 http://ysar.net/