1

I'm using Python 2.7.2. and I want to open and use a dictionary I created in my shell. My problem is, when I try to import this dictionary into my shell it can't find the file because python is just looking into the 'my documents' folder.

My question is, how can I navigate to the correct folder (just one folder further in 'my documents' folder.

I am using a Macintosh.

thegrinner
12.4k5 gold badges44 silver badges67 bronze badges
asked Mar 31, 2014 at 15:43

3 Answers 3

1

You can add custom path to your script as:

import sys
sys.path.append('/Users/username/')
answered Mar 31, 2014 at 15:45
Sign up to request clarification or add additional context in comments.

Comments

0

Another way is to set the PYTHONPATH environment variable to /User/username in your shell. Since you know about your shell, I expect that you already know how to edit your shell resource script. You could also add it to your .profile file in which case it should be available even if you change which shell you happen to be using.

answered Apr 1, 2014 at 0:53

Comments

0

If you don't want to "hardwire" the system path, but want to use a relative folder, you could get the name of the working directory and add your subdirectory to that...

subdirname = 'myfolder'
curdir = os.getcwd()
newdir = os.path.join(curdir,subdirname)
sys.path.append(newdir)
answered Apr 1, 2014 at 2:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.