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

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself