This seems like a pretty uncommon use case. But are there applications to other contexts where we might want easy line continuation?
-CHB On Tue, Feb 4, 2020 at 6:55 AM Paul Moore <p.f.mo...@gmail.com> wrote: > On Tue, 4 Feb 2020 at 10:39, Steven D'Aprano <st...@pearwood.info> 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' > > '79985304335099507553127683875317177019959423' > > '8596428121188033664754218345562493168782883') > > > > 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\ > > 79985304335099507553127683875317177019959423\ > > 8596428121188033664754218345562493168782883 > > > > Or if you don't like backslashes, trailing underscores are currently > > illegal, so we could use them: > > > > P = 29674495668685510550154174642905332730771991_ > > 79985304335099507553127683875317177019959423_ > > 8596428121188033664754218345562493168782883 > > > > > > Thoughts? > > 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. > > Paul > _______________________________________________ > 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/YOE53K3626PBQWBRX6V4YWWQMSGJRITX/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/54DUBW34JWZ3R7L2XD22G5JKLVQJJTRP/ Code of Conduct: http://python.org/psf/codeofconduct/