Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: PEP 378: Format Specifier for Thousands Separator

Reply
Thread Tools

Re: PEP 378: Format Specifier for Thousands Separator

 
 
Chris “Kwpolska” Warrick
Guest
Posts: n/a
 
      05-21-2013
On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
<(E-Mail Removed)> wrote:
> Thank you, but let me rephrase it. I'm already using str.format() but I'dlike to use '%' (BINARY_MODULO) operator instead.


There is no real reason to do this. `str.format()` is the new shiny
thing you should be using all the time. Also, '%' is BINARY_MODULO
(where did you even get that name from?) if and only if you have two
numbers, and it performs the modulo division (eg. 27 % 5 = 2)

> 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


This will make your code unportable and useless, depending on one
patch you made. Please don’t do that. Instead,

> >>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))

> Number = 12,345
>
> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut!


In Python? Tough luck, every int is signed. And it isn’t just a
sledgehammer, it’s something worse. Just do that:

>>> sys.stdout.write('Number = {:,.0f}\n'.format(x))


Much more peaceful.

You can also do a print, like everyone sane would. Where did you
learn Python from? “Python Worst Practice for Dummies”?

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail | always bottom-post
http://asciiribbon.org | http://caliburn.nl/topposting.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno Python 1 05-24-2013 02:29 AM
Re: PEP 378: Format Specifier for Thousands Separator Ned Deily Python 0 05-21-2013 05:44 AM
PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno Python 0 05-21-2013 05:17 AM
Rough draft: Proposed format specifier for a thousands separator Raymond Hettinger Python 39 03-22-2009 05:04 PM
Formatting Number With Thousands Separator Douglas Javascript 12 04-10-2004 03:09 AM



Advertisments