[issue45892] Improve REPL with the underscore separators for int/float

2021-11-24 Thread Alex


New submission from Alex :

I often use to the Python REPL to perform some simple calculations (typically 
some combinatorial or probabilities computation).
I believe it would be a nice improvement if the number displayed in the REPL 
would be formatted as if f"{result:_}" was given (with the underscore 
separators). For example:

 >>> 36 ** 7
 78_364_164_096

As I understand things:
* the REPL always shows the __repr__
* updating the __repr__ for int/float is a no-no for backward compatibility 
reasons

If these assumptions are correct (please correct me if this is wrong), then I 
guess this cannot be implemented, unless I missed something?

--
components: Interpreter Core
messages: 406934
nosy: alexprengere
priority: normal
severity: normal
status: open
title: Improve REPL with the underscore separators for int/float
type: behavior
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45892] Improve REPL with the underscore separators for int/float

2021-11-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

We can't change the repr of int/float.

However, you can use sys.displayhook to achieve what you want:

import sys

def displayhook(o):
if o is None:
return
__builtins__._ = None
if isinstance(o, (int, float)):
print(format(o, '_'))
else:
print(repr(o))
__builtins__._ = o

sys.displayhook = displayhook

Then:

>>> 12312312
12_312_312
>>> 123123e123
1.23123e+128
>>> None
>>> 'test'
'test'

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45892] Improve REPL with the underscore separators for int/float

2021-11-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

Oops, the float example should be:

>>> 123123.9
123_123.9

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45892] Improve REPL with the underscore separators for int/float

2021-11-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

And you can probably use sitecustomize.py to import this.

Since I don't see any action item here, I'm going to close this issue.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45892] Improve REPL with the underscore separators for int/float

2021-11-25 Thread Alex


Alex  added the comment:

Thanks a lot Eric for your answers, I did not know about sys.displayhook.
Now I know I can easily implement this myself, but the larger question would 
be: "do we want to update the default displayhook for those simple use cases".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com