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
  • 7,642
  • 11
  • 35
  • 72
Brandon
  • 171
  • 1
  • 3
  • 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
  • 23,210
  • 7
  • 49
  • 68
Himanshu Mishra
  • 7,642
  • 11
  • 35
  • 72