Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'cpython': 0.05; '21,': 0.07; 'made.': 0.07; 'skip:` 10': 0.07; 'subject:PEP': 0.07; 'string': 0.09; 'default.': 0.09; 'modulo': 0.09; 'pep': 0.09; 'performs': 0.09; 'screen.': 0.09; 'tutorials,': 0.09; 'python': 0.11; 'def': 0.12; 'thread': 0.14; '"programming': 0.16; '"python': 0.16; "'%s'": 0.16; 'analysing': 0.16; 'did:': 0.16; 'does,': 0.16; 'fancy': 0.16; 'gpg': 0.16; 'luck,': 0.16; 'sane': 0.16; 'skip:> 20': 0.16; 'specifier': 0.16; 'str.format()': 0.16; 'unsigned': 0.16; 'worse.': 0.16; 'worst': 0.16; 'wrote:': 0.18; 'looked': 0.18; '(where': 0.19; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'python?': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'instead.': 0.24; 'integer': 0.24; 'received:65.55.116': 0.24; 'skip:{ 20': 0.24; 'java': 0.24; 'looks': 0.24; 'question': 0.24; "i've": 0.25; 'source': 0.25; '+0200': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:- 40': 0.29; '[1]': 0.29; 'patch': 0.29; 'besides': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; 'that.': 0.31; 'url:wiki': 0.31; '>>>>': 0.31; 'division': 0.31; 'python"': 0.31; 'this.': 0.32; 'everyone': 0.33; 'actual': 0.34; 'date:': 0.34; "i'd": 0.34; 'message.': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'done': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'email addr:python.org': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'new': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 're:': 0.63; 'real': 0.63; 'such': 0.63; 'more': 0.64; 'love': 0.65; 'email name:python-list': 0.65; 'charset:windows-1252': 0.65; 'online': 0.71; '8bit%:100': 0.72; 'safe': 0.72; 'cut': 0.74; 'as:': 0.81; '(s)': 0.84; 'isn\x92t': 0.84; 'it\x92s': 0.84; 'me!': 0.84; 'safe.': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; '8bit%:58': 0.91; 'carlos': 0.91; 'mistakes': 0.93; 'tough': 0.93; 'url:tk': 0.95; '2013': 0.98 X-TMN: [ENBKp69QNsSArRWHX62N1fwFMIGDKKOU] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: PEP 378: Format Specifier for Thousands Separator Date: Tue, 21 May 2013 22:39:35 +0300 Importance: Normal In-Reply-To: References: , , Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 21 May 2013 19:39:35.0791 (UTC) FILETIME=[ECA9A7F0:01CE565A] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 103 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369165185 news.xs4all.nl 15879 [2001:888:2000:d::a6]:49832 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45684 ----------------------------------------=0A= > From: kwpolska@gmail.com=0A= > Date: Tue=2C 21 May 2013 21:06:11 +0200=0A= > Subject: Re: PEP 378: Format Specifier for Thousands Separator=0A= > To: carlosnepomuceno@outlook.com=0A= > CC: python-list@python.org=0A= >=0A= > On Tue=2C May 21=2C 2013 at 8:49 PM=2C Carlos Nepomuceno=0A= > wrote:=0A= >> Thank you=2C but let me rephrase it. I'm already using str.format() but = I'd like to use '%' (BINARY_MODULO) operator instead.=0A= >=0A= > There is no real reason to do this. `str.format()` is the new shiny=0A= > thing you should be using all the time. Also=2C '%' is BINARY_MODULO=0A= > (where did you even get that name from?) if and only if you have two=0A= > numbers=2C and it performs the modulo division (eg. 27 % 5 =3D 2)=0A= =0A= I did:=0A= =0A= >>> def fmt(s):=0A= ...=A0=A0=A0=A0 return '%s' % s=0A= ...=0A= >>> import dis=0A= >>> dis.dis(fmt)=0A= =A0 2=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0 LOAD_CONST=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 1 ('%s')=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 3 LOAD_FAST=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 0 (s)=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 6 BINARY_MODULO=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 7 RETURN_VALUE=0A= >>>=0A= =0A= Then I've looked for 'BINARY_MODULO' in "Python/ceval.c" and found:=0A= =0A= =A0=A0=A0=A0=A0=A0=A0 case BINARY_MODULO:=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 w =3D POP()=3B=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 v =3D TOP()=3B=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (PyString_CheckExact(v))=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 x =3D PyString_Format(v=2C w)= =3B=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 x =3D PyNumber_Remainder(v=2C= w)=3B=0A= =0A= =0A= Then I've looked for 'PyString_Format' and found it in "Objects/stringobjec= t.c"=0A= =0A= Analysing the code of "stringobject.c" I've found formatint() and formatlon= g().=0A= =0A= I'm not using str.format() because it's slower than '%' and because I love = '%'. str.format() looks like Java shit to me!=0A= =0A= >> So=2C the question is: Where would I change the CPython 2.7.5 source cod= e to enable '%' (BINARY_MODULO) to format using the thousands separator lik= e str.format() does=2C such as:=0A= >>=0A= >>>>>sys.stderr.write('%=2Cd\n' % 1234567)=0A= >> 1=2C234=2C567=0A= >=0A= > This will make your code unportable and useless=2C depending on one=0A= > patch you made. Please don=92t do that. Instead=2C=0A= =0A= I'm just learning how to improve things! =3B)=0A= =0A= >>>>> sys.stdout.write('Number =3D %s\n' % '{:=2C.0f}'.format(x))=0A= >> Number =3D 12=2C345=0A= >>=0A= >> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut= !=0A= >=0A= > In Python? Tough luck=2C every int is signed. And it isn=92t just a=0A= > sledgehammer=2C it=92s something worse. Just do that:=0A= >=0A= >>>> sys.stdout.write('Number =3D {:=2C.0f}\n'.format(x))=0A= >=0A= > Much more peaceful.=0A= =0A= Indeed! I just cut and pasted my code to create an example for the message.= The actual format operation isn't done at the sys.stdout.write().=0A= =0A= > You can also do a print=2C like everyone sane would. Where did you=0A= > learn Python from? =93Python Worst Practice for Dummies=94?=0A= =0A= lol I'm learning from my big mistakes up to now and a ton of online tutoria= ls=2C besides "Dive into Python" (2004)[1]=2C "Python Programming" (2012)[2= ] and "Programming Python=2C 3rd Ed" (2006) [print]=0A= =0A= print isn't thread safe. That's why I've chosen sys.stdout.write() -- it's = faster and thread safe by default.=0A= =0A= I don't need any fancy formating=2C just need to send the string to screen.= =0A= =0A= =0A= [1] http://www.diveintopython.net/=0A= [1] http://en.wikibooks.org/wiki/Python_Programming=0A= =0A= > --=0A= > Kwpolska | GPG KEY: 5EAAEA16=0A= > stop html mail | always bottom-post=0A= > http://asciiribbon.org | http://caliburn.nl/topposting.html =