How to check source code of a python method?

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 stringobject.c in the Objects directory of the Python source code. This isdigits method is implemented from line 3392 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.

Tags:

Python

Methods