Skip to content
Advertisement

How to get the path of a function in Python?

I want to obtain the file path of a function in Python.

How to do it?

For example,

JavaScript

Thank you.

Advertisement

Answer

You can use the getfile() function from the inspect module for this purpose.

For example, given the following files:

inspect-example.py

JavaScript

external_def.py

JavaScript

Executing inspect_example.py produces the following output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement