[Tutor] Unicode to Ascii
Steven D'Aprano
steve at pearwood.info
Mon Sep 26 20:45:35 EDT 2016
On Tue, Sep 27, 2016 at 03:46:25AM +0530, srinivas devaki wrote:
> How can I convert Unicode to Ascii by stripping of any non ascii characters.
>
> one way is to filter on s like
>
> ascii = ''.join(filter(lambda x: 0 <= ord(x) < 256, unicode_string))
>
> but are there any other simple ways ?
See also my reply to Bruce just now, but the easiest way is to encode to
bytes, then back to text:
ascii = unicode_string.encode('ascii', 'ignore').decode('ascii')
--
Steve
More information about the Tutor
mailing list