[Tutor] Trouble in dealing with special characters.

Sunil Tech sunil.techspk at gmail.com
Fri Dec 7 03:36:16 EST 2018


Hi Alan,

I am using Python 2.7.8
>>> tx = "MOUNTAIN VIEW WOMEN’S HEALTH CLINIC"
>>> tx.decode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19:
ordinal not in range(128)

How to know whether in a given string(sentence) is there any that is not
ASCII character and how to replace?

On Fri, Dec 7, 2018 at 2:01 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 07/12/2018 07:58, Sunil Tech wrote:
>
> > I have a trouble with dealing with special characters in Python Below is
> > the sentence with a special character(apostrophe) "MOUNTAIN VIEW WOMEN’S
> > HEALTH CLINIC" with actually should be "MOUNTAIN VIEW WOMEN'S HEALTH
> CLINIC
> > ".
>
> How do you define "special characters"?
> There is nothing special about the apostraphe. It is just as
> valid a character as all the other characters.
> What makes it special to you?
>
> > Please help, how to identify these kinds of special characters and
> replace
> > them with appropriate ASCII?
>
> What is appropriate ASCII?
> ASCII only has 127 characters.
> Unicode has thousands of characters.
> How do you want to map a unicode character into ASCII?
> There are lots of options but we can't tell what you
> think is appropriate.
>
> Finally, character handling changed between Python 2 and 3
> (where unicode became the default), so the solution will
> likely depend on the Python version you are using.
> Please tell us which.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list