Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29176

Re: Least-lossy string.encode to us-ascii?

Received by 10.224.207.197 with SMTP id fz5mr608875qab.3.1347639326150; Fri, 14 Sep 2012 09:15:26 -0700 (PDT)
Received by 10.236.87.71 with SMTP id x47mr934125yhe.6.1347639326127; Fri, 14 Sep 2012 09:15:26 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!v8no3864562qap.0!news-out.google.com!da15ni3445qab.0!nntp.google.com!v8no2665916qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Fri, 14 Sep 2012 09:15:25 -0700 (PDT)
In-Reply-To <mailman.640.1347571498.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=62.203.75.40; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_
NNTP-Posting-Host 62.203.75.40
References <mailman.640.1347571498.27098.python-list@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> (permalink)
Subject Re: Least-lossy string.encode to us-ascii?
From wxjmfauth@gmail.com
Cc Python <python-list@python.org>
Injection-Date Fri, 14 Sep 2012 16:15:26 +0000
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:29176

Show key headers only | View raw


Le jeudi 13 septembre 2012 23:25:27 UTC+2, Tim Chase a écrit :
> 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ço móvil" 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.
> 

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 = 'Lætitia  cœur  éléphant  français  LUŸ  Stoß  Erklärung  stören'
>>> libfrancais.SpecMajuscules(s)
'LAETITIA  COEUR  ELEPHANT  FRANCAIS  LUY  STOSS  ERKLAERUNG 
STOEREN'

>>> r = 'LAETITIA  COEUR  ELEPHANT  FRANCAIS  LUY  STOSS  ERKLAERUNG STOEREN'
>>> r.encode('ascii', 'strict').decode('ascii', 'strict') == r
True

PS Avoid Py3.3 :-)

jmf

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Least-lossy string.encode to us-ascii? Tim Chase <python.list@tim.thechases.com> - 2012-09-13 16:26 -0500
  Re: Least-lossy string.encode to us-ascii? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-14 03:49 +0000
  Re: Least-lossy string.encode to us-ascii? wxjmfauth@gmail.com - 2012-09-14 09:15 -0700
    Re: Least-lossy string.encode to us-ascii? Terry Reedy <tjreedy@udel.edu> - 2012-09-14 16:43 -0400
      Re: Least-lossy string.encode to us-ascii? wxjmfauth@gmail.com - 2012-09-15 01:58 -0700
      Re: Least-lossy string.encode to us-ascii? wxjmfauth@gmail.com - 2012-09-15 01:58 -0700
  Re: Least-lossy string.encode to us-ascii? wxjmfauth@gmail.com - 2012-09-14 09:15 -0700

csiph-web