This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wyz23x2
Recipients wyz23x2
Date 2020-07-09.01:30:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594258221.41.0.149493736122.issue41250@roundup.psfhosted.org>
In-reply-to
Content
The current syntax is this for thousand separators:
f'{var:,}'
It will return this when var is 1234567:
'1,234,567'
But sometimes we need a way to insert them in other places. For example:
123456789 → '1,2345,6789' (4)
62938757312 → '6,29387,57312' (5)
This could be done like this:
Idea 1:
Add a new method to string:
string.sep(num: int_or_float, interval: int_or_iterable = 3, 
           sepchar: str = ',')
>>> import string
>>> string.sep(1234567, 3)
'1,234,567'
>>> string.sep(1234567890, range(1, 4))
'1,23,456,7890'
>>> string.sep('Hello')
TypeError: Invalid number 'Hello'
>>> string.sep(12345678, sepchar=' ')
'12 345 678'
>>> string.sep(123456789, 4, '|')
'1|2345|6789'

Idea 2: (Not as powerful as above)
(Future)
>>> f'{123456789:4,}'
'1,2345,6789'
>>> f'{62938757312:5,}'
'6,29387,57312'
>>> f'{1234567:,}' # Equal to f'{1234567:3,}'
'1,234,567'
(Current)
>>> f'{12345678:5,}' # 5 discarded
'12,345,678'
History
Date User Action Args
2020-07-09 01:30:21wyz23x2setrecipients: + wyz23x2
2020-07-09 01:30:21wyz23x2setmessageid: <1594258221.41.0.149493736122.issue41250@roundup.psfhosted.org>
2020-07-09 01:30:21wyz23x2linkissue41250 messages
2020-07-09 01:30:20wyz23x2create