This seems like a pretty uncommon use case.
But are there applications to other contexts where we might want easy line continuation?
On Tue, 4 Feb 2020 at 10:39, Steven D'Aprano <firstname.lastname@example.org> wrote:
> I've been doing some work with large ints, of well over 100 digits. For
> example, this number has 131 digits:
> P = 29674495668685510550154174642905332730771991799853043350995075531276838753171770199594238596428121188033664754218345562493168782883
> Sometimes I'm tempted to write numbers like that as follows:
> P = int('29674495668685510550154174642905332730771991'
> which is nicer to read, except for the minor annoyance of the call to
> int and the string delimiters.
> That got me thinking that it might be Nice To Have if we could split
> long int literals across multiple lines:
> P = 29674495668685510550154174642905332730771991\
> Or if you don't like backslashes, trailing underscores are currently
> illegal, so we could use them:
> P = 29674495668685510550154174642905332730771991_
My immediate instinct was underscores so I favour that over
backslashes. And I think that if you need to write huge numbers like
that then having a better way to break them up is important (you don't
use internal underscores at all in your example, which surprises me,
as that would be the first thing I'd do).
But I would ask, do you *really* type numbers like that in manually???
I can imagine them being output from another program, or from
information in a webpage, that you copy and paste in here, but I'd be
more likely to address that with a comment above the definition,
saying how to regenerate the number, and that it was copy-and-pasted
from that output. If you're copy/pasting, having to reformat is more
awkward, rather than less.
Can you share a bit more about why you need to do this? In the
abstract, having the ability to split numbers over lines seems
harmless and occasionally useful, but conversely it's not at all
obvious why anyone would be doing this in real life.
Python-ideas mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at https://email@example.com/message/YOE53K3626PBQWBRX6V4YWWQMSGJRITX/
Code of Conduct: http://python.org/psf/codeofconduct/
Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython