pythonintellij-ideapycharmipython

ipython or pycharm underscore thousand separator in numeric literals


I am using pycharm with ipython enabled in debugger.
How can I get nuumeric literals to be displayed/printed with underscode as a thousands separator.
Instead of this 107010000 I need 107_010_000. Please refer to the screenshot where I marked places I want such formatting to be applied.
I already seen this post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004398280-DataGrip-2019-2-1-showing-underscore-for-thousands-separator-in-editor

Update:
And I have seen How to print number with commas as thousands separators?
My question is not how to format numeric literal using python programming language. It is about representation in ipython or pycharm debugger. I need this by default.
For instance if I do this:

a = 1000
print(a)

I want to see:

1_000



enter image description here


Solution

  • I know this is an old question, but since python 3.6 which supports f-strings you can achive the desired result as follows:

    a = 1000
    print(f'{a:_}')
    

    It also works without using a variable:

    print(f'{1000:_}')
    

    In both cases the output is 1_000. Not very elegant, but it works.