Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'ascii': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'toss': 0.09; ':-)': 0.13; 'encoding': 0.15; "'o',": 0.16; 'decode': 0.16; 'mean,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'stdlib.': 0.16; 'stripped': 0.16; 'sufficient,': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'tim': 0.18; '>>>': 0.18; '(or': 0.18; 'option.': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'forgot': 0.27; 'opposed': 0.27; 'header:X-Complaints-To:1': 0.28; 'decide': 0.28; 'chase': 0.29; 'thursday,': 0.30; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'text': 0.34; 'text.': 0.35; 'so,': 0.35; 'doing': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'similar': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'wanted': 0.36; 'characters': 0.36; 'depends': 0.36; 'keeps': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'recipient': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'information': 0.63; 'want,': 0.65; 'subject': 0.66; 'dict.': 0.84; 'received:fios.verizon.net': 0.84; 'wanted,': 0.84; 'approach.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Least-lossy string.encode to us-ascii? Date: Fri, 14 Sep 2012 16:57:29 -0400 References: <50524F6F.6070604@tim.thechases.com> <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347656285 news.xs4all.nl 6894 [2001:888:2000:d::a6]:38762 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29189 On 9/13/2012 10:09 PM, Mark Tolonen wrote: > On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: >> On 09/13/12 18:36, Terry Reedy wrote: >>> 'keep as much information as possible' would mean an effectively >>> lossless transliteration, which you could do with a dict. >>> {: 'o', : 'c,' (or pick something that woul= d >> Vlastimil's solution kept the characters but stripped them of their >> accents/tildes/cedillas/etc, doing just what I wanted, all using the >> stdlib. Hard to do better than that :-) You mean, hard to do better than what you think you want, as opposed to=20 what you said you wanted in both the subject line and the text line I=20 quoted. What you need depends on why you need ascii only text and what=20 the recipient will do with the ascii only text. Print it on an=20 ascii-only printer? Or something similar? If so, a lossy encoding may be = sufficient, but why not let the recipient decide to toss info? > How about using UTF-7 for transmission and decode on the other end? > This keeps the transmission all 7-bit, and no loss. > > >>> s=3Du"servi=C3=A7o m=C3=B3vil".encode('utf-7') > >>> print s > servi+AOc-o m+APM-vil > >>> print s.decode('utf-7') > servi=C3=A7o m=C3=B3vil Nice. I was barely aware of and forgot that option. This and similar=20 suggestions to use existing methods is much better than my hackish approa= ch. --=20 Terry Jan Reedy