Message373367
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' |
|
Date |
User |
Action |
Args |
2020-07-09 01:30:21 | wyz23x2 | set | recipients:
+ wyz23x2 |
2020-07-09 01:30:21 | wyz23x2 | set | messageid: <1594258221.41.0.149493736122.issue41250@roundup.psfhosted.org> |
2020-07-09 01:30:21 | wyz23x2 | link | issue41250 messages |
2020-07-09 01:30:20 | wyz23x2 | create | |
|