- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to retrieve source code from Python objects?
We use the getsource() method of inspect module to get the source code of the function.
Returns the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An IOError is raised if the source code cannot be retrieved.
If the function is compiled from a string, stream or imported from a compiled file, then you cannot retrieve its source code.
We import the inspect module and retrieve the source code for given script as follows
#baz.py import inspect class foo: def bar(): print 'Hello' print(inspect.getsource(foo))
C:/Users/TutorialsPoint1/~.py class foo: def bar(): print 'Hello'
- Python Code Objects
- Accessing HTML source code using Python Selenium.
- Source code of ABAP reports without restriction
- Rearrange the given source code in C++
- How to retrieve the MSI package product code using PowerShell?
- How can I source a Python file from another Python file?
- How to Find out the source code of a transaction in SAP?
- Installing MySQL from Source
- Displaying Source code of RFC in SAP system
- How to retrieve Python module path?
- How to access Python objects within objects in Python?
- How to Fetch source code of the transaction note in SAP R/3?