Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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; '"""': 0.07; 'args': 0.07; 'python3': 0.07; 'string': 0.09; 'function,': 0.09; 'received:209.85.219': 0.09; 'statements': 0.09; 'subject:string': 0.09; 'thx': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '**kwargs)': 0.16; '**kwargs):': 0.16; '->': 0.16; 'at.': 0.16; 'braces': 0.16; 'formatted': 0.16; 'gpg': 0.16; 'src': 0.16; 'subject:format': 0.16; 'subject:python3': 0.16; 'url:file': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'looked': 0.18; 'file,': 0.19; '8bit%:5': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'source': 0.25; '>': 0.26; 'pass': 0.26; 'code:': 0.26; 'skip:_ 20': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'reply.': 0.31; '25,': 0.31; 'invoke': 0.31; 'class': 0.32; 'url:python': 0.33; 'implemented': 0.33; 'at:': 0.34; 'received:209.85': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'curious': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'skip:& 10': 0.38; 'same.': 0.38; 'pm,': 0.38; 'skip:_ 30': 0.39; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'url:mail': 0.40; 'how': 0.40; 'ian': 0.60; 'url:about': 0.61; 'simply': 0.61; "you're": 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'mar': 0.68; '26,': 0.68; 'containing': 0.69; 'url:me': 0.69; 'press': 0.70; 'special': 0.74; 'url:cpython': 0.84; 'involved.': 0.91; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=TSp0nN0HOHHRrQ201lMHl4ghKyx6NWsNsyusOK0dWJM=; b=ohMIG5FUn3lDwTJ2DSAF1i+Uyoq7sVJig1RhrDErtCGFP6oOtpwOtRc5XS6lxkAYle qhMnGqnQLqsPU0pWdegqE+3aP6Ogm5l0Ne2to/A3ff4L5fdaCdIKQf8VSm/ZEUyha15G 235thAXvJJ9rva8tlTd7CMWXa20H/xsl8MKqpq7YFdBTjlEKBI7wFsPCTHwJ7wnGxA9f iMKRpjM2ffhQg4Rp3QSL/RzbiEtlgtTkPmBgjTHRhvLi2zNasg64CGM95uUe2McXAnMz gPM6KXJewhwAoRdEEfC3OhTqdpZy+5wNTnrezPSSfC2k9nu+nVJ8kewV5WnoOizJ39I8 D1Yw== MIME-Version: 1.0 X-Received: by 10.182.98.109 with SMTP id eh13mr1953179obb.50.1364295071046; Tue, 26 Mar 2013 03:51:11 -0700 (PDT) X-Originating-IP: [59.66.130.213] In-Reply-To: References: Date: Tue, 26 Mar 2013 18:51:10 +0800 Subject: Re: python3 string format From: Shiyao Ma To: Ian Kelly Content-Type: multipart/alternative; boundary=14dae93a15c314342a04d8d1b306 X-Gm-Message-State: ALoCoQn0ZgRxLmGZvJMy7h5Hd9IUK/qa4bm2v5saRGqw586G9Q3kpVI8p9hL2VC7/GbWB0zAmLVi Cc: Python 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: 136 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364295074 news.xs4all.nl 6947 [2001:888:2000:d::a6]:59846 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41877 --14dae93a15c314342a04d8d1b306 Content-Type: text/plain; charset=ISO-8859-1 Thx for your reply. I am using pycharm and simply press "go to declaration" which directs me to a py file, containing the following code: def format(*args, **kwargs): # known special case of str.format """ S.format(*args, **kwargs) -> string Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). """ pass I am curious how you find the corresponding c source code. On Tue, Mar 26, 2013 at 2:16 PM, Ian Kelly wrote: > On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma wrote: > > HI. > > one thing confuses me. > > It is said in the pep3101 that "{}".format (x) will invoke the method > > x.__format__ > > However, I looked at the src of python3 and found: > > in class str(object), the format simply contains a pass statement > > in class int(object), things is the same. > > I don't know what source you're looking at. In CPython, both of those > types are implemented in C, not Python, so there would be no pass > statements involved. > > The int.__format__ method is implemented at: > > http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373 > > It mainly just calls the _PyLong_FormatAdvancedWriter function, which is > at: > > > http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399 > > The str.__format__ method similarly is implemented at: > > > http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851 > > and calls the _PyUnicode_FormatAdvancedWriter function at: > > > http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363 > -- > http://mail.python.org/mailman/listinfo/python-list > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom --14dae93a15c314342a04d8d1b306 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thx for your reply.=A0
I am using pycharm and simply press "go to = declaration" which directs me to a py file, containing the following c= ode:
def format(*args, **kwargs): # known special case of st= r.format
=A0 =A0 =A0 =A0 """
=A0 =A0 =A0 =A0 S.format(= *args, **kwargs) -> string
=A0 =A0 =A0 =A0=A0
=A0 = =A0 =A0 =A0 Return a formatted version of S, using substitutions from args = and kwargs.
=A0 =A0 =A0 =A0 The substitutions are identified by b= races ('{' and '}').
=A0 =A0 =A0 =A0 """
=A0 =A0 =A0 =A0 pass
I am curious how you find the corresponding c source code.

<= div class=3D"gmail_quote">On Tue, Mar 26, 2013 at 2:16 PM, Ian Kelly <= ian.g.kelly@gmail.com> wrote:
On Mon, Mar 25, 2013 at 10= :24 PM, Shiyao Ma <i@introo.me> wr= ote:
> HI.
> one thing confuses me.
> It is said in the pep3101 that "{}".format (x) will invoke t= he method
> x.__format__
> However, I looked at the src of python3 and found:
> in class str(object), the format simply contains a pass statement
> in class int(object), things is the same.

I don't know what source you're looking at. =A0In CPython, bo= th of those
types are implemented in C, not Python, so there would be no pass
statements involved.

The int.__format__ method is implemented at:

http://hg.python.org/cpython/file/3c437e591499= /Objects/longobject.c#l4373

It mainly just calls the _PyLong_FormatAdvancedWriter function, which is at= :

http://hg.python.org/cpython/file/3c437e= 591499/Python/formatter_unicode.c#l1399

The str.__format__ method similarly is implemented at:

http://hg.python.org/cpython/file/3c437e59= 1499/Objects/unicodeobject.c#l12851

and calls the _PyUnicode_FormatAdvancedWriter function at:

http://hg.python.org/cpython/file/3c437e= 591499/Python/formatter_unicode.c#l1363
--
http://mail.python.org/mailman/listinfo/python-list



-- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net --recv-keys 307CF736
More on: http://about= .me/introom

--14dae93a15c314342a04d8d1b306--