-2

How can I view the source code of a particular Standard Library and/or an External Library? I would like to see the Python code, not the underling C code.

I am trying to find this to see how experienced programmers write their code. I already looked at the Where do I find the python standard library code? but the answer just seems to be most is written in C.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Andy
  • 919
  • 2
  • 9
  • 22
  • https://stackoverflow.com/questions/11385576/where-do-i-find-the-python-standard-library-code – rdas Apr 23 '19 at 13:14
  • 2
    Possible duplicate of [Where do I find the python standard library code?](https://stackoverflow.com/questions/11385576/where-do-i-find-the-python-standard-library-code) – MyNameIsCaleb Apr 23 '19 at 13:14
  • 2
    It depends upon the module, but some are written in C and you'll find no Python code for them. For a module written in Python, you can import it and check its `__file__` attribute: `import numpy; numpy.__file__`. – Right leg Apr 23 '19 at 13:15
  • 1
    Some of the modules are written in C (assuming you are using the C implementation of python) and there is no python code. – cdarke Apr 23 '19 at 13:16
  • 1
    One useful related utility in [IPython](https://ipython.org/) is that if you type `something??`, where `something` is a Python function, class or module, you can see its source code. Otherwise, you can use [`inspect.getsource`](https://docs.python.org/3/library/inspect.html#inspect.getsource). – jdehesa Apr 23 '19 at 13:17

1 Answers1

4

The main repo of the standard library is hosted here: https://github.com/python/cpython/blob/3.7/Lib/

This can also be found on the typical Python installation in the same location (i.e. subfolder Lib).