PDA

View Full Version : [SOLVED] noob python question



T2manner
October 8th, 2008, 01:12 AM
How do i change directories?
i'm trying to test some of of my modules in the terminal, but they aren't in the home folder and i'm not sure how to change directories to get to the module

LaRoza
October 8th, 2008, 01:21 AM
How do i change directories?
i'm trying to test some of of my modules in the terminal, but they aren't in the home folder and i'm not sure how to change directories to get to the module

See 6.1.2 http://www.python.org/doc/2.5.2/tut/node8.html

You could also move to the directory they are in before starting Python (cd).

The way to change directories in Python is (but not the solution to this problem) is "os.chdir()".

T2manner
October 8th, 2008, 01:59 AM
I read that, but I couldn't find how to solve my problem.

TreeFinger
October 8th, 2008, 02:34 AM
$ sudo apt-get install ipython
$ ipython


In [1]: %cd 'dir/here'

T2manner
October 8th, 2008, 02:50 AM
i don't want ipython..
i want to use regular python...

TreeFinger
October 8th, 2008, 02:51 AM
i don't want ipython..
i want to use regular python...

You are using 'regular' python. Just a different interpreter. I don't see what the big deal is. Quick solution for your question.

LaRoza
October 8th, 2008, 02:52 AM
i don't want ipython..
i want to use regular python...

What is the directory structure of the module? (Absolute paths please).

T2manner
October 8th, 2008, 03:09 AM
the module is in /home/tyler/Code
all i want to do is import the module in terminal without having to change the directory before i start python

LaRoza
October 8th, 2008, 03:12 AM
the module is in /home/tyler/Code
all i want to do is import the module in terminal without having to change the directory before i start python

Add this to your code:



import sys
sys.path.append('/home/tyler/Code')


(Unless "Code" is the module, then use /home/tyler)

T2manner
October 8th, 2008, 03:19 AM
thankyou very much :]