4

I'm new to this and wondering, where's all the code for the modules and packages and stuff that you can import located on my computer.

Can anyone give me a short lesson and help me out?

Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74
Brandon
  • 321
  • 1
  • 4
  • 10

1 Answers1

5

Suppose you want to know the location of xyz module. You do this on the interpreter

>>> import xyx
>>> xyz.__file__

You'll get the location of the pyc file from where your module is being imported.

You can also simply do

>>> xyz

to get the module name and the location of the module.

To know about all the possible locations from where the modules are imported, use sys.path:

>>> import sys
>>> sys.path

This will give you the list of the locations where Python searches for a module when you do import.

Hope that helps.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74