To be short, suppose I have a string 'next'
,
next = "123rpq"
and I can apply a str
method .isdigit()
to 'next'
. So my question is how to check the implementation of this method. Hence is there a thing like inspect.getsource(somefunction)
to get the source code of a 'method'?
UPDATE: see comment about variable name 'next'
below.
For modules, classes, functions and a few other objects you can use inspect.getfile
or inspect.getsourcefile
. However, for builtin objects and methods this will result in a TypeError
. As metioned by C0deH4cker, builtin objects and methods are implemented in C, so you will have to browse the C source code. isdigit
is a method of the builtin string object, which is implemented in the file unicodeobject.c
in the Objects
directory of the Python source code. This isdigit
method is implemented from line 11,416 of this file. See also my answer here to a similar but more general question.
The isdigit()
method you are talking about is a builtin method of a builtin datatype. Meaning, the source of this method is written in C, not Python. If you really wish to see the source code of it, then I suggest you go to http://python.org and download the source code of Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With