Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'case.': 0.05; 'subject:skip:s 10': 0.05; 'preserves': 0.09; 'scripts,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; ':-)': 0.13; "'replace')": 0.16; "'strict')": 0.16; 'elephant': 0.16; 'us-ascii': 0.16; 'usage,': 0.16; '\xc3\xa9crit\xc2\xa0:': 0.16; 'tim': 0.18; '>>>': 0.18; "i'd": 0.22; 'cc:2**0': 0.23; 'task': 0.23; "i've": 0.23; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'coding': 0.27; 'possible,': 0.27; "doesn't": 0.28; 'correct': 0.28; 'chase': 0.29; 'case,': 0.29; 'convert': 0.29; 'becomes': 0.30; 'german': 0.32; "skip:' 20": 0.32; 'received:google.com': 0.34; 'text': 0.34; 'text.': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'characters': 0.36; 'stock': 0.36; 'anything': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'received:209.85.214': 0.39; 'where': 0.40; 'subject:-': 0.40; 'from:no real name:2**0': 0.60; 'information': 0.63; 'french': 0.64; 'erkl\xc3\xa4rung': 0.84; 'received:209.85.214.184': 0.84; 'received:mail- ob0-f184.google.com': 0.84 Newsgroups: comp.lang.python Date: Fri, 14 Sep 2012 09:15:25 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=62.203.75.40; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_ References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 62.203.75.40 MIME-Version: 1.0 Subject: Re: Least-lossy string.encode to us-ascii? From: wxjmfauth@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347639335 news.xs4all.nl 6922 [2001:888:2000:d::a6]:49875 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29177 Le jeudi 13 septembre 2012 23:25:27 UTC+2, Tim Chase a =C3=A9crit=C2=A0: > 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. So >=20 > "servi=C3=A7o m=C3=B3vil" becomes "servico movil". Is there anything sto= ck >=20 > that I've missed? I can do mystring.encode('us-ascii', 'replace') >=20 > but that doesn't keep as much information as I'd hope. >=20 Interesting case. It's where the coding of characters meets characters usage, scripts, typography, linguistic features. I cann't discuss the Portugese case, but in French and in German one way to achieve the task is to convert the text in uppercases. It preserves a correct text. >>> s =3D 'L=C3=A6titia c=C5=93ur =C3=A9l=C3=A9phant fran=C3=A7ais LU= =C5=B8 Sto=C3=9F Erkl=C3=A4rung st=C3=B6ren' >>> libfrancais.SpecMajuscules(s) 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG=20 STOEREN' >>> r =3D 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG STOE= REN' >>> r.encode('ascii', 'strict').decode('ascii', 'strict') =3D=3D r True PS Avoid Py3.3 :-) jmf