Devanagari int literals [was Re: Should non-security 2.7 bugs be fixed?]

Anuradha Laxminarayan lanuradha at gmail.com
Sun Jul 19 08:25:30 CEST 2015


On Sunday, July 19, 2015 at 10:15:37 AM UTC+5:30, Steven D'Aprano wrote:
> On Sun, 19 Jul 2015 01:52 pm, Rustom Mody wrote:
>
> > Not to mention actively hostile attitude to discussions that could at the
> > moment be tangential to current CPython. See (and whole thread)
> > https://mail.python.org/pipermail/python-ideas/2015-May/033708.html
>
> I stand by my comments there. I have no disagreement with your aim to build
> a specialised language for teaching functional programming. I don't believe
> that should be Python.
>
>
> > JFTR: My kids (um... students) have just managed to add devanagari
> > numerals to python.
> > ie we can now do
> >
> >>>> १ + २
> > 3
>
> That is actually quite awesome, and I would support a new feature that set
> the numeric characters to a particular script, e.g. Latin, Arabic,
> Devanagari, whatever, and printed them in that same script. It seems
> unfortunate that १ + २ prints as 3 rather than ३.

Thanks. [I am part of this team]

>
> Python already, and has for many years, supported non-ASCII digits in string
> conversions. This is in Python 2.4:
>
> py> int(u'१२')
> 12
> py> float(u'.१२')
> 0.12
>

Very useful to know!

>
> so the feature goes back a long time.
>
> I think that Python should allow int and float literals using any sequences
> of digits from the same language, e.g. 12 or १२ but not १2. One might have
> an interpreter hook which displayed ints and floats using non-ASCII digits,
> or one might even build that function into the intepreter, e.g. have a
> global setting which tells ints and floats what digits to use, e.g.:
>
> sys.setdigits('Devanagari')
>


Currently our code works with UTF-8 byte sequences not unicode codepoints
because thats how tokenizer.c is structured: messy and not generalizable (easily) to things beyond devanagari.  How far this can be improved (without too deep surgery) is not quite clear yet.

In other words, this generality is nice to talk about but easier said than done at the moment.


More information about the Python-list mailing list