Categories
Python Answers

How to retrieve a module’s path with Python?

Spread the love

Sometimes, we want to retrieve a module’s path with Python.

In this article, we’ll look at how to retrieve a module’s path with Python.

How to retrieve a module’s path with Python?

To retrieve a module’s path with Python, we can call os.path.abspath.

For instance, we write

import os

path = os.path.abspath(a_module.__file__)

to call os.path.abspath with a_module.__file__ to get the absolute path of the a_module module.

Conclusion

To retrieve a module’s path with Python, we can call os.path.abspath.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *