Dan Sommers wrote:
> On Wed, 5 Feb 2020 11:09:16 +0000
> Jonathan Fine jfine2...@gmail.com wrote:
> > How about something like:
> > def t1(argv):
> > ...     value = 0
> > ...     for n in argv:
> > ...         value = 1_000
> > ...         value += n
> > ...     return value
> > t1(123, 456, 789)
> > 123456789
> > Similarly, for define t2 to use 1_000_000, t3 to use 1_000_000_000
> > and so
> > on, instead of 1_000. For really big numbers, you might want to use t10.
> > Someone previously asked about a "base"; your idea could be extended to
> accommodate same:
> > def tbuilder(base):
> >     def t(argv):
> >         value = 0
> >         for n in argv:
> >             value = base
> >             value += n
> >         return value
> >     return t
> > tbuilder(1000)(123, 456, 789)
> > 123456789

This won't work when leading zeros are involved, e.g. consider `123_006_789`: 
`t(123, 006, 789)` gives a SyntaxError. Also it's weird that when we want to 
write an int literal that we end up with two function calls and individual 
numbers as arguments (+ you'd need to have that function handy in the first 
place). It would be clearer to use a kw-only argument `base=1000` but even then 
it doesn't really convey they idea of a literal.

> > If you're dealing with really big integers (say 1000 digits or more)
> > then you might be want to use https://pypi.org/project/gmpy2/, in
> > which case you'll appreciate the extra flexibility provided by
> > t10. (This would allow t10 to return a gmpy integer, if import gmpy2
> > succeeds.)
> > +1
> > Finally, perhaps really big numbers should be stored
> > as data, rather
> > than placed in source code files. (For example, this would allow these
> > large pieces of data to be verified, via a secure hash.)
> > +1
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HR73ICP2D43OTOCRZAXFU2LPNOXNQI3E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to