import inspect

class TestClassA:
    def __init__(self):
        print "Hello"
print inspect.getsource(TestClassA)

Workig for me in pycharm, If you try to use it in interactive mode,run this

import os
import inspect
inspect.getsource(os)

Two methods you mentioned does the same thing only return types are different Check https://docs.python.org/2/library/inspect.html#inspect.getsourcelines

Answer from P. Dev on Stack Overflow
🌐
Python
docs.python.org › 3 › library › inspect.html
inspect — Inspect live objects
Source code: Lib/inspect.py The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › inspect-module-in-python
Inspect Module in Python - GeeksforGeeks
July 15, 2025 - The inspect module in Python is useful for examining objects in your code. Since Python is an object-oriented language, this module helps inspect modules, functions and other objects to better understand their structure.
🌐
Real Python
realpython.com › ref › stdlib › inspect
inspect | Python Standard Library – Real Python
The Python inspect module provides several useful tools to help you get information about live objects, such as modules, classes, methods, functions, tracebacks, and the objects’ source code.
🌐
Cypress
cypress.io
Testing Frameworks for Javascript | Write, Run, Debug | Cypress
Simplify front-end testing with Cypress' open-source app. Explore our versatile testing frameworks for browser-based applications and components.
🌐
Astral
docs.astral.sh › uv › pip › environments
Using environments | uv
March 24, 2026 - The --system flag is also used to opt in to mutating system environments. For example, the --python argument can be used to request a Python version (e.g., --python 3.12), and uv will search for an interpreter that meets the request. If uv finds a system interpreter (e.g., /usr/lib/python3.12), then the --system flag is required to allow modification of this non-virtual Python environment.
Find elsewhere
🌐
W3Schools
w3schools.com › python › ref_module_inspect.asp
Python inspect Module
The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects.
🌐
Python Pool
pythonpool.com › home › blog › python inspect module and its applications with examples
Python Inspect Module and its Applications With Examples - Python Pool
March 10, 2022 - Python inspect module provides in-built functions for fetching programmatical information on live objects, including modules, classes...
🌐
scikit-learn
scikit-learn.org › stable › modules › generated › sklearn.ensemble.RandomForestClassifier.html
RandomForestClassifier — scikit-learn 1.8.0 documentation
Note: the search for a split does not stop until at least one valid partition of the node samples is found, even if it requires to effectively inspect more than max_features features.
🌐
Expo
expo.dev
Expo
Write native code with the Expo Modules API and config plugins.
🌐
University of Auckland
cs.auckland.ac.nz › references › python › 3.2.3-docs › library › inspect.html
27.12. inspect — Inspect live objects — Python v3.2.3 documentation
April 22, 2012 - Returns a named tuple ModuleInfo(name, suffix, mode, module_type) of values that describe how Python will interpret the file identified by path if it is a module, or None if it would not be identified as a module.
🌐
ArjanCodes
arjancodes.com › blog › how-to-analyze-python-classes-with-inspect-module
Inspect Module Guide for Python Classes | ArjanCodes
April 4, 2024 - For those seeking to take their ... trove. It provides several functions to retrieve information about live objects, such as modules, classes, methods, functions, tracebacks, and the Python frame stack....
🌐
Cockpit Project
cockpit-project.org
Cockpit Project — Cockpit Project
Inspect and interact with systemd-based services · Use a terminal on a remote server in your local web browser · Switch between multiple Cockpit servers · Extend Cockpit’s functionality by installing a growing list of apps and add-ons · Write your own custom modules to make Cockpit do anything you want ·
🌐
Python
docs.python.org › 3 › py-modindex.html
Python Module Index — Python 3.14.5rc1 documentation
modules | Python » · 3.14.5rc1 Documentation » · Python Module Index · | Theme · Auto · Light · Dark | _ | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | z · « · index · modules | Python » · 3.14.5rc1 Documentation » ·
🌐
W3Schools
w3schools.com › python › python_ref_modules.asp
Python Standard Library Modules (3.13)
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... This page lists the built-in modules that ship with the Python 3.13 Standard Library.
🌐
Martin Heinz
martinheinz.dev › blog › 82
All The Ways To Introspect Python Objects at Runtime | Martin Heinz | Personal Website & Blog
October 3, 2022 - There are a couple ways to do that - the best option is to use callable(), if you're however running Python 3.1, then you'd have to check for presence of __call__ attribute using hasattr function instead. Last option would be to use isfunction() from inspect module, be careful with that one though, as it will return False for builtin functions such as sum, len or range because these are implemented in C, so they're not Python functions.
🌐
PyPI
pypi.org › project › micropython-inspect
micropython-inspect
October 11, 2016 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser