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


Groups > comp.lang.python > #29177

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

Newsgroups comp.lang.python
Date 2012-09-14 09:15 -0700
References <mailman.640.1347571498.27098.python-list@python.org>
Subject Re: Least-lossy string.encode to us-ascii?
From wxjmfauth@gmail.com
Message-ID <mailman.711.1347639335.27098.python-list@python.org> (permalink)

Show all headers | 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 | 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