Re: python3 string format

Discussion in 'Python' started by Ian Kelly, Mar 26, 2013.

  1. Ian Kelly

    Ian Kelly Guest

    On Tue, Mar 26, 2013 at 4:51 AM, Shiyao Ma <> wrote:
    > 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 would guess that Python declaration is maintained and used by
    PyCharm for code intelligence.

    > I am curious how you find the corresponding c source code.


    The str object is mostly implemented in Objects/unicodeobject.c. The
    int object is mostly implemented in Objects/longobject.c. Other
    built-in types can also be found in that directory. Each has a
    PyMethodDef[] global array that declares the implementations of the
    object's methods. Finding the implementation is then just a matter of
    grepping the source for its name.

    The function I pointed you to before implements the str.__format__
    method. The str.format method itself is at:

    http://hg.python.org/cpython/file/84e73ace3d7e/Objects/stringlib/unicode_format.h#l942

    I'm not sure why that one is implemented in a .h file.
    Ian Kelly, Mar 26, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Berg
    Replies:
    0
    Views:
    330
    Andrew Berg
    Jun 16, 2012
  2. Chris Angelico
    Replies:
    3
    Views:
    151
    Mark Lawrence
    Mar 1, 2013
  3. Shiyao Ma

    python3 string format

    Shiyao Ma, Mar 26, 2013, in forum: Python
    Replies:
    0
    Views:
    108
    Shiyao Ma
    Mar 26, 2013
  4. Ian Kelly

    Re: python3 string format

    Ian Kelly, Mar 26, 2013, in forum: Python
    Replies:
    0
    Views:
    103
    Ian Kelly
    Mar 26, 2013
  5. Shiyao Ma

    Re: python3 string format

    Shiyao Ma, Mar 26, 2013, in forum: Python
    Replies:
    0
    Views:
    121
    Shiyao Ma
    Mar 26, 2013
Loading...

Share This Page