How do you find out in what folder is the Python imported module stored?
Experience Level: Junior
Tags: Python
Answer
Each imported module has the location where it was found stored in module's __file__ attribute.
Example:
File main.py
import basic_math
print(basic_math.__file__)
File basic_math.py
def add(x, y):
return x+y
Related Python job interview questions
How can you display all modules that are currently loaded in your Python program?
Python JuniorWhat happens if you import a same module in Python twice and the module contains code print("hello")?
Python JuniorWhen would you use the print() function in Python?
Python JuniorWhat is the print() function good for in Python?
Python JuniorHow do you obtain a value of search path in Python?
Python Junior