Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'ascii': 0.07; 'behave': 0.07; 'implicit': 0.07; "shouldn't": 0.07; 'suggesting': 0.07; 'python': 0.08; '"default': 0.09; 'garbage': 0.09; 'okay': 0.09; 'silently': 0.09; 'tty': 0.09; 'wrong,': 0.09; 'output': 0.11; 'exception': 0.12; "'replace')": 0.16; 'ascii,': 0.16; 'disagree.': 0.16; 'encode': 0.16; 'error)': 0.16; 'fail,': 0.16; 'garbage.': 0.16; 'ttys,': 0.16; 'wrong).': 0.16; "wouldn't": 0.17; 'header:In-Reply-To:1': 0.21; 'subject:problem': 0.22; 'smart': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'code': 0.24; 'somebody': 0.25; 'specify': 0.25; 'received:209.85.161': 0.26; 'string': 0.26; 'windows': 0.26; 'message-id:@mail.gmail.com': 0.28; 'problem': 0.28; 'sorry,': 0.29; 'unicode': 0.29; 'do.': 0.30; 'eat': 0.30; 'seem': 0.32; "can't": 0.32; 'to:addr:python-list': 0.33; 'file': 0.34; 'thinking': 0.34; 'fail': 0.34; 'that,': 0.34; 'explicit': 0.35; 'platform,': 0.35; '(with': 0.36; 'skip:o 20': 0.37; 'data.': 0.37; 'too.': 0.37; 'received:google.com': 0.37; 'change': 0.37; 'received:209.85': 0.37; 'anything': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; 'view': 0.66; 'strange': 0.68; 'want,': 0.74; 'ascii.': 0.91; 'step.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=6vApdlQlIQHmcAl7ZsI1bP2mjBuRJ+JwJpNfMct8y40=; b=p90mVTVlWiMGFjLW8utIE9bIIbvtLDreDInxn4RNjRaUlvpphqv50TMuTZKZYnU0KP ZXn+Y3L+85ZPv21/kpcVihjY9L+u5AUD1mjmrrvoY2m0tuW3ERcITamho91XqqAeySDv PQCVylK/lsdECv1HSz3mQbrymIU3BDq5DQksY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=etW+bTib2yVQkt7vRpE8dUhS+ulvAnrIJQVAP4ii4h3LngUuIOrJMUu1f388fJWqyn OuFJUsDoyzpGDJIoPsep0JMxVLSEwO+oqcHJ35CmLe4Q54FY+KFzJxhvdW2TLfKO1esW 4X054MbWbM8syXHdwaoNrszlpXt9WeFSEhy80= MIME-Version: 1.0 In-Reply-To: <4df2340d$0$30577$a729d347@news.telepac.pt> References: <4df02e04$0$1779$a729d347@news.telepac.pt> <4df137a7$0$30580$a729d347@news.telepac.pt> <4df16f2e$0$30572$a729d347@news.telepac.pt> <8762oewjao.fsf@benfinney.id.au> <4df2340d$0$30577$a729d347@news.telepac.pt> From: Ian Kelly Date: Fri, 10 Jun 2011 10:58:56 -0600 Subject: Re: the stupid encoding problem to stdout To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 34 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307725174 news.xs4all.nl 49045 [::ffff:82.94.164.166]:52456 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7384 2011/6/10 S=E9rgio Monteiro Basto : > ok after thinking about this, this problem exist because Python want be > smart with ttys, which is in my point of view is wrong, should not encode= to > utf-8, because tty is in utf-8. Python should always encode to the same > thing. If the default is ascii, should always encode to ascii. > yeah should send to tty in ascii, if I send my code to a guy in windows > which use tty with cp1000whatever , shouldn't give decoding errors and > should send in ascii . You can't have your cake and eat it too. If Python needs to output a string in ascii, and that string can't be represented in ascii, then raising an exception is the only reasonable thing to do. You seem to be suggesting that Python should do an implicit output.encode('ascii', 'replace') on all Unicode output, which might be okay for a TTY, but you wouldn't want that for file output; it would allow Python to silently create garbage data. And what if you send your code to somebody with a UTF-16 terminal? You try to output ASCII to that, and you're just going to get complete garbage. If you want your output to behave that way, then all you have to do is specify that with an explicit encode step. > If we want we change default for whatever we want, but without this "defa= ult > change" Python should not change his behavior depending on output. > yeah I prefer strange output for a different platform, to a decode errors= . Sorry, I disagree. If your program is going to fail, it's better that it fail noisily (with an error) than silently (with no notice that anything is wrong).