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


Groups > comp.lang.python > #13234

Re: How do I automate the removal of all non-ascii characters from my code?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <alec.taylor6@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'ascii': 0.07; 'subject:code': 0.07; 'python': 0.08; '8bit%:78': 0.09; '>>>>': 0.09; 'subject:characters': 0.09; 'url:peps': 0.09; 'declared;': 0.16; 'from:addr:alec.taylor6': 0.16; 'from:name:alec taylor': 0.16; 'subject:non': 0.16; 'syntaxerror:': 0.16; 'url:pep-0263': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'convert': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'tue,': 0.23; 'sep': 0.23; 'worked': 0.23; 'pm,': 0.24; 'input': 0.24; 'string': 0.26; 'url:mailman': 0.28; 'exit': 0.29; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'subject:?': 0.31; 'url:listinfo': 0.33; 'character': 0.34; 'test': 0.34; 'like:': 0.34; 'skip:" 20': 0.35; 'subject:How': 0.35; 'file': 0.36; 'url:python': 0.36; '8bit%:86': 0.37; 'but': 0.37; 'something': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'non': 0.38; 'subject:: ': 0.39; 'e.g.': 0.39; "there's": 0.39; 'received:74.125': 0.39; 'subject:from': 0.40; "it's": 0.40; 'where': 0.40; 'kind': 0.61; 'details': 0.65; '8bit%:75': 0.67; 'skip:\xd0 20': 0.77; '11:33': 0.84; 'subject:removal': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=g0pqXuXqoD7kMSLgHpZmKkPrOZ27LEnpHiCsPdvuZNM=; b=j/PQWIUb5yUee7tfgGz9E1opubIFxDV+UZzbxJXneMvqEVTuKm9nOPT0T0QCq5953t 3HdDkn5ogKMTinQm/vDW5hIYp1pPYdbCsrODhzm6Hdm55B6hybV0z3fpQyKjEZbaaEyy I+Slcnp9jUGwj6v5k9iela/MVjZx18QqSqSSA=
MIME-Version 1.0
In-Reply-To <CAHzaPEM7OURL_UESEEJGBVHOaTT0TS6LgVf+SV2UuGQg8czS6w@mail.gmail.com>
References <CAO+9iGc0f7vFLrjjm24vzZqoMV04eL4fBQrYOTfDt-eYCNEacQ@mail.gmail.com> <4E6DC028.1020101@islandtraining.com> <CAO+9iGfHABoWnz-Podk9J5D3EJFgQ-9th=ky2Z-uW8MbQJA12A@mail.gmail.com> <CAO+9iGe2JcUHY8u+KEZfv3r8VmBdJ9h9NLwL3nO2Wpm80zRT2Q@mail.gmail.com> <mailman.1021.1315817058.27778.python-list@python.org> <4e6dc7b4$0$29986$c3e8da3$5496439d@news.astraweb.com> <ee50be9b-2710-423b-9c69-744cc173ac85@dq7g2000vbb.googlegroups.com> <CAHzaPEM7OURL_UESEEJGBVHOaTT0TS6LgVf+SV2UuGQg8czS6w@mail.gmail.com>
Date Wed, 14 Sep 2011 01:02:05 +1000
Subject Re: How do I automate the removal of all non-ascii characters from my code?
From Alec Taylor <alec.taylor6@gmail.com>
To Vlastimil Brom <vlastimil.brom@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1074.1315926128.27778.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315926128 news.xs4all.nl 2522 [2001:888:2000:d::a6]:36232
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:13234

Show key headers only | View raw


Hmm, nothing mentioned so far works for me...

Here's a very small test case:

>>> python -u "Convert to Creole.py"
  File "Convert to Creole.py", line 1
SyntaxError: Non-ASCII character '\xe2' in file Convert to Creole.py
on line 1, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details
>>> Exit Code: 1

Line 1: a=u'''≤'''.encode("ascii", "ignore").decode("ascii")

On Tue, Sep 13, 2011 at 11:33 PM, Vlastimil Brom
<vlastimil.brom@gmail.com> wrote:
> 2011/9/13 ron <vacorama@gmail.com>:
>>
>> Depending on the load, you can do something like:
>>
>> "".join([x for x in string if ord(x) < 128])
>>
>> It's worked great for me in cleaning input on webapps where there's a
>> lot of copy/paste from varied sources.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> Well, for this kind of dirty "data cleaning" you may as well use e.g.
>
>>>> u"äteöxt ÛÜÝ wiÉÊËÌthÞßà áânoûüýþn ASɔɕɖCɗɘəɚɛIɗɘəɚɛIεζ iηθιn жзbetийклweeჟრსn .ტუ..ფ".encode("ascii", "ignore").decode("ascii")
> u'text  with non ASCII in between ...'
>>>>
>
> vbr
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Re: How do I automate the removal of all non-ascii characters from my code? Stefan Behnel <stefan_ml@behnel.de> - 2011-09-12 10:43 +0200
  Re: How do I automate the removal of all non-ascii characters from my code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-12 18:49 +1000
    Re: How do I automate the removal of all non-ascii characters from my code? Dave Angel <davea@ieee.org> - 2011-09-12 08:09 -0400
    Re: How do I automate the removal of all non-ascii characters from my code? jmfauth <wxjmfauth@gmail.com> - 2011-09-12 07:47 -0700
      Re: How do I automate the removal of all non-ascii characters from my code? "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2011-09-12 22:39 +0100
        Re: How do I automate the removal of all non-ascii characters from my code? jmfauth <wxjmfauth@gmail.com> - 2011-09-13 00:49 -0700
          Re: How do I automate the removal of all non-ascii characters from my code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-13 18:15 +1000
            Re: How do I automate the removal of all non-ascii characters from my code? jmfauth <wxjmfauth@gmail.com> - 2011-09-13 02:04 -0700
    Re: How do I automate the removal of all non-ascii characters from my code? ron <vacorama@gmail.com> - 2011-09-13 05:31 -0700
      Re: How do I automate the removal of all non-ascii characters from my code? Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-09-13 15:33 +0200
      Re: How do I automate the removal of all non-ascii characters from my code? Alec Taylor <alec.taylor6@gmail.com> - 2011-09-14 01:02 +1000
        Re: How do I automate the removal of all non-ascii characters from my code? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-09-13 18:29 +0300
      Re: How do I automate the removal of all non-ascii characters from my code? Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-09-13 20:13 +0200

csiph-web