Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python- list': 0.10; ':-)': 0.13; "'o',": 0.16; '-tkc': 0.16; 'decode': 0.16; 'reedy': 0.16; 'stdlib.': 0.16; 'stripped': 0.16; 'us- ascii': 0.16; 'wrote:': 0.17; 'tim': 0.18; '>>>': 0.18; '(or': 0.18; 'sort': 0.21; "i'd": 0.22; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'chase': 0.29; '8bit%:5': 0.29; 'thursday,': 0.30; 'could': 0.32; 'print': 0.32; 'received:google.com': 0.34; 'text': 0.34; 'doing': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'characters': 0.36; 'keeps': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'subject:-': 0.40; 'information': 0.63; 'dict.': 0.84; 'wanted,': 0.84 Newsgroups: comp.lang.python Date: Thu, 13 Sep 2012 19:09:38 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=67.189.99.135; posting-account=U-tUWAoAAAD04wGl_yNltUZRFMSEBwR3 References: <50524F6F.6070604@tim.thechases.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 67.189.99.135 MIME-Version: 1.0 Subject: Re: Least-lossy string.encode to us-ascii? From: Mark Tolonen To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, Terry Reedy 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347588580 news.xs4all.nl 6883 [2001:888:2000:d::a6]:55475 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29100 On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: > On 09/13/12 18:36, Terry Reedy wrote: >=20 > > On 9/13/2012 5:26 PM, Tim Chase wrote: >=20 > >> I've got a bunch of text in Portuguese and to transmit them, need to >=20 > >> have them in us-ascii (7-bit). I'd like to keep as much information >=20 > >> as possible,just stripping accents, cedillas, tildes, etc. >=20 > >=20 >=20 > > 'keep as much information as possible' would mean an effectively=20 >=20 > > lossless transliteration, which you could do with a dict. >=20 > > {: 'o', : 'c,' (or pick something that would= =20 >=20 > > never occur in normal text of the sort you are transmitting), ...} >=20 >=20 >=20 > Vlastimil's solution kept the characters but stripped them of their >=20 > accents/tildes/cedillas/etc, doing just what I wanted, all using the >=20 > stdlib. Hard to do better than that :-) >=20 >=20 >=20 > -tkc How about using UTF-7 for transmission and decode on the other end? This k= eeps the transmission all 7-bit, and no loss. >>> s=3Du"servi=E7o m=F3vil".encode('utf-7') >>> print s servi+AOc-o m+APM-vil >>> print s.decode('utf-7') servi=E7o m=F3vil -Mark