[Tutor] Trouble in dealing with special characters.

Cameron Simpson cs at cskk.id.au
Sat Dec 8 17:23:59 EST 2018


On 07Dec2018 21:20, Steven D'Aprano <steve at pearwood.info> 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 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
>'abc\xcf\x80'

Wow. I did not know that! I imagined Python 2 would have simply rejected 
such a string (out of range characters -- ordinals >= 256 -- in a "byte" 
string).

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list