Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'url:pypi': 0.03; 'subject:skip:s 10': 0.05; "'replace')": 0.16; '-tkc': 0.16; 'reliably': 0.16; 'us-ascii': 0.16; 'tim': 0.18; '>>>': 0.18; 'import': 0.21; 'received:209.85.216.46': 0.21; "i'd": 0.22; "haven't": 0.23; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; 'possible,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'chase': 0.29; 'becomes': 0.30; 'url:python': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'text': 0.34; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'skip:u 20': 0.36; 'but': 0.36; 'url:org': 0.36; 'stock': 0.36; 'anything': 0.36; 'enough': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'information': 0.63; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=C1CwlcnIa+Dr9P57c2JdVFeHpHrZKUFzF1/JndXrOdQ=; b=OrZfMk4tAzTxNHUbSBKqg1wCrHCywm48UXEYroqYfuL/0Db5YcR9zlFNtzZ0qsQOq9 85G7LQAx9Oj54lYgDiwmvtVgrqTnqhugriXC3INGQrkRwlK1o3GNMoU9JNB/7vx0UADC W1B8zYtcscMT/SE+JmFj5VOBxYEU/jIXZOs+sqPdYiSUSnPq7oQczLKQQTlihfdBeGg8 zMhsnkwjp1v+cIjL0JGDlft7s31F6ojK7SUcoVvVO68V9KxFw8BGr2ubkHywXL8ZxjiM T5fWq/Wrzrv/GlGdFCVLf53X1gtuOmd3T3FHoGvkkvafSVH+5OaHJyx2owqnUcZRXVG3 lDkA== MIME-Version: 1.0 In-Reply-To: <50524F6F.6070604@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> Date: Thu, 13 Sep 2012 23:44:18 +0200 Subject: Re: Least-lossy string.encode to us-ascii? From: Vlastimil Brom 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.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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347572661 news.xs4all.nl 6867 [2001:888:2000:d::a6]:59934 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29079 2012/9/13 Tim Chase : > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). I'd like to keep as much information > as possible, just stripping accents, cedillas, tildes, etc. So > "servi=E7o m=F3vil" becomes "servico movil". Is there anything stock > that I've missed? I can do mystring.encode('us-ascii', 'replace') > but that doesn't keep as much information as I'd hope. > > -tkc > Hi, would something like the following be enough for your needs? Unfortunately, I can't check it reliably with regard to Portuguese. >>> import unicodedata >>> unicodedata.normalize("NFD", u"servi=E7o m=F3vil").encode("ascii", "ign= ore").decode("ascii") u'servico movil' >>> There is also "Unidecode", but I haven't used it myself sofar... http://pypi.python.org/pypi/Unidecode/ hth, vbr