IDLE module path

A forum for general discussion of the Python programming language.

IDLE module path

Postby peredur » Thu Jan 23, 2014 6:56 pm

If I create a new directory for a new project in Python, this directory will not be on the default python path as shown in sys.path.

In IDLE, if I work solely in files and not at the interactive prompt and save both files into this new directory I can import one into the other with no problem. So say I save the files to the directory ~/python-projects/myproject, and that the files are called main.py and mymodule.py, I can import mymodule.py into main.py by doing 'import mymodule'. All is well and good.

However, if I also have the IDLE interactive prompt open and try to do 'import mymodule', it fails. It even fails after I change the working directory using:

import os
os.chdir('...').

Listing sys.path shows me that the current directory ('.') is not on the path. This is very inconvenient since it means I can't try things out interactively. Is there any way I can get IDLE to look for files in it's current working directory?

I'm using xubuntu, by the way, and am very new to Python; so apologies if this is a naive question.

Thanks in advance


PAE
peredur
 
Posts: 1
Joined: Thu Jan 23, 2014 6:40 pm

Re: IDLE module path

Postby metulburr » Thu Jan 23, 2014 7:08 pm

Use a terminal instead of IDLE. I have no problems when using the terminal.

Listing sys.path shows me that the current directory ('.') is not on the path

sys.path is the merging of the home directory of the top-level file (or an empty string to designate the current working directory), any PYTHONPATH directories, the contents of any .pth files path you created, and the standard library directories. You can also append to this list any directory you want.

The current directory does not need to be in that path, because you will have easy access to all its subdirectories and files.

Is there any way I can get IDLE to look for files in it's current working directory?

the interpreter opens in the current directory

if I work solely in files and not at the interactive prompt and save both files into this new directory I can import one into the other with no problem.

You will mostly be doing this anyways. The interpreter is a testing area, not the way to code.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 5 guests