-1

Possible Duplicate:
Importing Python modules from different working directory

I want to import a file that is on the following directory:

 E:\edX\cs6.00x\week6\ProblemSet6

I was trying:

import 'E:\edX\cs6.00x\week6\ProblemSet6\ps6'

where ps6.py is the file i wanted imported in the IDLE, but it complains about a sintax error in the last ', how can I fix that?

0

4 Answers 4

4

You can

import sys
sys.path.append("E:\edX\cs6.00x\week6\ProblemSet6")

and then simply

import ps6
Sign up to request clarification or add additional context in comments.

Comments

1
import sys
sys.path.append("E:\edX\cs6.00x\week6\ProblemSet6\ps6")

import file_in_ps6.py

1 Comment

hmm... ps6 is the file I want to open, not a folder
0
import imp
foo = imp.load_source('ps6', 'E:\edX\cs6.00x\week6\ProblemSet6\ps6.py')
foo.BlaBla()

Comments

0

One possible solution could be to put a mth suffixed file in your sys.prefix directory.

>>> import sys
>>> sys.prefix
'F:\\F-ProgramFiles\\Python-3.2.3'
>>>

So in my case the directory is 'F:\F-ProgramFiles\Python-3.2.3'. I can create a file named forexample 'mymodules.mth' in this directory (with the suffix .mth) which contains at least two lines with the following syntax:

<module1 name without module filename suffix>
<absolute file path to your module1 file>
<module2 name without module filename suffix>
<absolute file path to your module2 file>
<module3 name without module filename suffix>
<absolute file path to your module3 file>
        .
        .
        .

After that if you restart a new python session, normally you should have the visibility to your module and being able to import your desired module(s).

Regards,

Dariyoosh

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.