Search Path for Modules

Do you know how an interpreter works when a module is imported? When a module is imported the interpreter looks at the current directory for the file name. If its not in the current directory it looks into the list of directories specified by the environment variable PYTHONPATH. This is similar to the shell variable PATH. If PYTHONPATH is not set the interpreter looks at an installation dependent default path. In most cases the default path will be ‘.:usr/local/lib/python’.

We can modify the path as follows:

>>> import sys

>>> sys.path.append(‘path’)

the new path must be given in position of ‘path’.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 29, 2010, in Python. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: