python tip

Printing the file path of imported modules

We always use modules such as os, pygame etc. Ever thought about where they come from? If you did then here's how to find out!

import os
import pygame

print(os)
print(pygame)

Output:

<module 'os' from 'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python39\\lib\\os.py'>
<module 'pygame' from 'C:\\Users\\Dell\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pygame\\__init__.py'>