Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.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; 'redirected': 0.07; 'skip:\\ 20': 0.07; 'ascii': 0.09; 'encode': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'windows': 0.15; 'codec': 0.16; 'dangerous,': 0.16; "function's": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repr': 0.16; 'subject:3.3': 0.16; 'subject:python': 0.16; 'bit': 0.19; 'trying': 0.19; 'seems': 0.21; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'file.': 0.24; 'looks': 0.24; 'skip:" 30': 0.26; 'skip:_ 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'character': 0.29; "i'm": 0.30; 'bad.': 0.31; 'occurs': 0.31; 'pipe': 0.31; 'file': 0.32; 'run': 0.32; '(most': 0.33; 'problem': 0.35; "can't": 0.35; 'knows': 0.35; 'convert': 0.35; 'but': 0.35; 'responsible': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'skip:c 50': 0.60; 'simple': 0.61; 'received:109': 0.72; 'directed': 0.83 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robin Becker Subject: python 3.3 repr Date: Fri, 15 Nov 2013 11:28:15 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 109.174.168.73 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384514912 news.xs4all.nl 15865 [2001:888:2000:d::a6]:49989 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59510 I'm trying to understand what's going on with this simple program if __name__=='__main__': print("repr=%s" % repr(u'\xc1')) print("%%r=%r" % u'\xc1') On my windows XP box this fails miserably if run directly at a terminal C:\tmp> \Python33\python.exe bang.py Traceback (most recent call last): File "bang.py", line 2, in print("repr=%s" % repr(u'\xc1')) File "C:\Python33\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\xc1' in position 6: character maps to If I run the program redirected into a file then no error occurs and the the result looks like this C:\tmp>cat fff repr='┴' %r='┴' and if I run it into a pipe it works as though into a file. It seems that repr thinks it can render u'\xc1' directly which is a problem since print then seems to want to convert that to cp437 if directed into a terminal. I find the idea that print knows what it's printing to a bit dangerous, but it's the repr behaviour that strikes me as bad. What is responsible for defining the repr function's 'printable' so that repr would give me say an Ascii rendering? -confused-ly yrs- Robin Becker