malin...@163.com writes:

 > PEP 515 added underscore to numeric literals, it brings better
 > readability.
 > 
 >     PEP 515 -- Underscores in Numeric Literals
 >     https://www.python.org/dev/peps/pep-0515/
 > 
 > Is it possible to add _KB, _MB, _GB to numeric literals, for example:

With a bit of generalization, it's something that many scientific
users would like to see.  But I think if you follow the idea to some
logical extensions, you'll see that it's not a good idea.  The problem
is that adding them to literals would require that they be built in to
the parser.  But why stop at _KB?  Surely you need _KiB and _km and
_kg?  Should _m_s be interpreted as meter-seconds or meters/second?

Look up the units and siunits modules on PyPI for two examples of how
units could be handled in Python.  A few years ago there was a long
discussion about the design of a somewhat more powerful module like
siunits that could added to the standard library, and perhaps be given
a syntactic role eventually (so that you could write 10 kb instead of
10*kb).  I don't have time or energy to look up the thread, but
siunits seems to have most of the features proposed, so I doubt it's
worth your time to chase it down youself.  Unless you want the
*really* *long* version of the paragraph above. :-)

Steve
_______________________________________________
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/F7XQQVHYLLNFPNHQ2FRGELWS3HPKHU7X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to