File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -2444,6 +2444,50 @@ def relpath(path, start=None):
24442444 else :
24452445 return os .path .relpath (path , start )
24462446
2447+
2448+ def number_sep ( s ):
2449+ '''
2450+ Simple number formatter, adds commas in-between thousands. `s` can be a
2451+ number or a string. Returns a string.
2452+
2453+ >>> number_sep(1)
2454+ '1'
2455+ >>> number_sep(12)
2456+ '12'
2457+ >>> number_sep(123)
2458+ '123'
2459+ >>> number_sep(1234)
2460+ '1,234'
2461+ >>> number_sep(12345)
2462+ '12,345'
2463+ >>> number_sep(123456)
2464+ '123,456'
2465+ >>> number_sep(1234567)
2466+ '1,234,567'
2467+ >>> number_sep(-131072)
2468+ '-131,072'
2469+ '''
2470+ if not isinstance ( s , str ):
2471+ s = str ( s )
2472+ ret = ''
2473+ if s .startswith ('-' ):
2474+ ret += '-'
2475+ s = s [1 :]
2476+ c = s .find ( '.' )
2477+ if c == - 1 : c = len (s )
2478+ end = s .find ('e' )
2479+ if end == - 1 : end = s .find ('E' )
2480+ if end == - 1 : end = len (s )
2481+ for i in range ( end ):
2482+ ret += s [i ]
2483+ if i < c - 1 and (c - i - 1 )% 3 == 0 :
2484+ ret += ','
2485+ elif i > c and i < end - 1 and (i - c )% 3 == 0 :
2486+ ret += ','
2487+ ret += s [end :]
2488+ return ret
2489+
2490+
24472491def _so_suffix (use_so_versioning = True ):
24482492 '''
24492493 Filename suffix for shared libraries is defined in pep-3149. The
You can’t perform that action at this time.
0 commit comments