PEP 378: Format Specifier for Thousands Separator

Carlos Nepomuceno carlosnepomuceno at outlook.com
Tue May 21 14:49:28 EDT 2013


________________________________
> From: alyssonbruno at gmail.com 
> Date: Tue, 21 May 2013 09:03:13 -0300 
> Subject: Re: PEP 378: Format Specifier for Thousands Separator 
> To: python-list at python.org 
>  
> This work in 3.1+: 
>  
> $ python3 
> Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) 
> [GCC 4.4.5] on linux2 
> Type "help", "copyright", "credits" or "license" for more information. 
> >>> one_number = 1234567 
> >>> print('number={:,}'.format(one_number)) 
> number=1,234,567 
> >>> 
>  

Thank you, but let me rephrase it. I'm already using str.format() but I'd like to use '%' (BINARY_MODULO) operator instead.

I've looked into the source code of CPython 2.7.5 and I've found no evidence of the thousands separator been implemented on formatint() in "Objects/unicodeobject.c".

I also didn't find the _PyString_FormatLong() used in formatlong(). Where is _PyString_FormatLong() located?

So, the question is: Where would I change the CPython 2.7.5 source code to enable '%' (BINARY_MODULO) to format using the thousands separator like str.format() does, such as:

>>>sys.stderr.write('%,d\n' % 1234567)
1,234,567 		 	   		  


More information about the Python-list mailing list