How to see the source code of a function in python? | Sololearn: Learn to code for FREE!

0

How to see the source code of a function in python?

For example sha256 encoding function

4/11/2020 4:11:26 AM

karangreat

5 Answers

New Answer

+6

Have you tried this :) import inspect,this print(inspect.getsource(this)) edit: https://stackoverflow.com/questions/427453/how-can-i-get-the-source-code-of-a-python-function

+2

The source code for Python's built-in functions is written in c and can only be accessed by looking at the Python's source code (hosted on Mercurial or downloadable from https://www.python.org/downloads/source/)​. But you can get source code of methods and defined functions: https://code.sololearn.com/cE8HJLBJXSPK/?ref=app

+1

Daljeet Singh it is working but only for user defined functions not for inbuilt function 😞 https://code.sololearn.com/cAHsIKZvIkoC/?ref=app

0

PythonPip It's not working for time module https://code.sololearn.com/cRG8Yi32ChvX/?ref=app

0

karangreat Yeah, that is because it is coded in c language.