PEP 378: Format Specifier for Thousands Separator

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue May 21 23:08:54 EDT 2013


On Wed, 22 May 2013 05:56:53 +0300, Carlos Nepomuceno wrote:

> ----------------------------------------
>> From: steve+comp.lang.python at pearwood.info Subject: Re: PEP 378: Format
>> Specifier for Thousands Separator Date: Wed, 22 May 2013 02:42:56 +0000
>> To: python-list at python.org
>>
>> On Tue, 21 May 2013 23:22:24 +0300, Carlos Nepomuceno wrote:
>>
>>> Anyway, is it possible to overload str.__mod__() without deriving a
>>> class? I mean to have something like:
>>
>> No, not in Python. If you want to monkey-patch built-in classes on the
>> fly, with all the troubles that causes, use Ruby.
>>
>>
> So, the only alternative to have "'%,d' % x" rendering the thousands
> separator output would a C source code modification?

That's one alternative. But the language you would be then running will 
no longer be Python.

Another alternative would be to write a pre-processor that parses your 
Python source code, extracts any reference to the above, and replaces it 
with a call to the appropriate format call. But not only is that a lot of 
work for very little gain, but it's also more or less impossible to do in 
full generality. And again, what you are running will be something 
different than Python, it will be Python plus a pre-processor.


Don't fight the language. You will lose.



-- 
Steven



More information about the Python-list mailing list