Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45684
| 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 | <carlosnepomuceno@outlook.com> |
| 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 <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <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 | <CAMw+j7JdSe2CAs=FF0iYiN-KkmR7uy5g+D3muvFcpvR+HRquOw@mail.gmail.com> |
| References | <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl> <CADUW+M=Y7b=4ZEENVzx4p6YpVD8T0eG=qz7sz8+iEow-5-o+jQ@mail.gmail.com> <CAMw+j7JdSe2CAs=FF0iYiN-KkmR7uy5g+D3muvFcpvR+HRquOw@mail.gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1934.1369165185.3114.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
----------------------------------------
> From: kwpolska@gmail.com
> Date: Tue, 21 May 2013 21:06:11 +0200
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> To: carlosnepomuceno@outlook.com
> CC: python-list@python.org
>
> On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
> <carlosnepomuceno@outlook.com> wrote:
>> Thank you, but let me rephrase it. I'm already using str.format() but I'd like 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)
I did:
>>> def fmt(s):
... return '%s' % s
...
>>> import dis
>>> dis.dis(fmt)
2 0 LOAD_CONST 1 ('%s')
3 LOAD_FAST 0 (s)
6 BINARY_MODULO
7 RETURN_VALUE
>>>
Then I've looked for 'BINARY_MODULO' in "Python/ceval.c" and found:
case BINARY_MODULO:
w = POP();
v = TOP();
if (PyString_CheckExact(v))
x = PyString_Format(v, w);
else
x = PyNumber_Remainder(v, w);
Then I've looked for 'PyString_Format' and found it in "Objects/stringobject.c"
Analysing the code of "stringobject.c" I've found formatint() and formatlong().
I'm not using str.format() because it's slower than '%' and because I love '%'. str.format() looks like Java shit to me!
>> 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,
I'm just learning how to improve things! ;)
>>>>> 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.
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().
> You can also do a print, like everyone sane would. Where did you
> learn Python from? “Python Worst Practice for Dummies”?
lol I'm learning from my big mistakes up to now and a ton of online tutorials, besides "Dive into Python" (2004)[1], "Python Programming" (2012)[2] and "Programming Python, 3rd Ed" (2006) [print]
print isn't thread safe. That's why I've chosen sys.stdout.write() -- it's faster and thread safe by default.
I don't need any fancy formating, just need to send the string to screen.
[1] http://www.diveintopython.net/
[1] http://en.wikibooks.org/wiki/Python_Programming
> --
> Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
> stop html mail | always bottom-post
> http://asciiribbon.org | http://caliburn.nl/topposting.html
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-21 22:39 +0300
csiph-web