Re: [Tutor] Trouble in dealing with special characters.

2018-12-08 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 09:23:59AM +1100, Cameron Simpson wrote: > On 07Dec2018 21:20, Steven D'Aprano wrote: # Python 2 > txt = "abcπ" > > > >but it is a lie, because what we get isn't the string we typed, but the > >interpreters *bad guess* that we actually meant this: > > > txt >

Re: [Tutor] Trouble in dealing with special characters.

2018-12-08 Thread Cameron Simpson
On 07Dec2018 21:20, Steven D'Aprano wrote: On Fri, Dec 07, 2018 at 02:06:16PM +0530, Sunil Tech wrote: I am using Python 2.7.8 That is important information. Python 2 unfortunately predates Unicode, and when it was added some bad decisions were made. For example, we can write this in Python

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Mats Wichmann
On 12/7/18 3:20 AM, Steven D'Aprano wrote: >> How to know whether in a given string(sentence) is there any that is not >> ASCII character and how to replace? > > That's usually the wrong solution. That's like saying, "My program can't > add numbers greater than 100. How do I tell if a number is

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 02:06:16PM +0530, Sunil Tech wrote: > Hi Alan, > > I am using Python 2.7.8 That is important information. Python 2 unfortunately predates Unicode, and when it was added some bad decisions were made. For example, we can write this in Python 2: >>> txt = "abcπ" but it

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 01:28:18PM +0530, Sunil Tech wrote: > Hi Tutor, > > I have a trouble with dealing with special characters in Python There are no special characters in Python. There are only Unicode characters. All characters are Unicode, including those which are also ASCII. Start

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Alan Gauld via Tutor
On 07/12/2018 08:36, Sunil Tech wrote: > I am using Python 2.7.8 tx = "MOUNTAIN VIEW WOMEN’S HEALTH CLINIC" tx.decode() > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19: > ordinal not in range(128) >

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Sunil Tech
Hi Alan, I am using Python 2.7.8 >>> tx = "MOUNTAIN VIEW WOMEN’S HEALTH CLINIC" >>> tx.decode() Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19: ordinal not in range(128) How to know whether in a given

Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Alan Gauld via Tutor
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