How To Retrieve A Module’s Path?

In this tutorial, we will learn How To Retrieve A Module’s Path as modules the used for getting the results from other python programs or files where the coded programs are stored for further use. And some time we need certain modules to be used for different programs and for them we need to know the path of the module.

Here we are going to find the exact path of the module where exactly that module is being stored here the given code can be used for doing the same.

Module

Module’s Path

To get the path of the module we simply need to follow the code given below and execute it to get the full path of module.

To get the path of the desired module first we need to import that module so that we can get the path in python we know that we can import any inbuild or later created module directly by simply writing the name of the module followed by the import keyword.

As we import without knowing the exact location of the module where we have stored that module in files to get the path where exactly the module is stored to get the location in file manager.

import os

module_ path = os. path. abspath(__file__)
print( module_path)

The above two lines of code will get the path of the module os which is imported and the path will be saved in a variable module_path which is printed on the next line with the print statement.

 

To learn more about How To Retrieve A Module’s Path at get Module path.

Also, visit some Basic Python String Programs-1  to learn more about python programming and solve the problems related to it.

To learn more about different programming languages and solutions related to all the programming languages and get clear concepts visit beta python programing languages solutions.

Leave a Comment

%d bloggers like this: