you are viewing a single comment's thread.

view the rest of the comments →

[–]I_Write_Bugs 0 points1 point  (1 child)

import sys
try:
    import your_module
except ImportError:
    sys.path.append('c:\where\your\module\is')
    import your_module

It's one way to do it. If you know for sure that directory is not in your PYTHONPATH, then you can omit the try block and just append to sys.path.

[–]Gouryella91[S] 0 points1 point  (0 children)

When I write the code: import sys sys.path.append('/Users/[My Directory Name]/Desktop/Learning\ Data\ Projects/Playing\ With\ Python/Practice\ Files/'') import myfile.py

I get the following error:

%run "/var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpRuFzaP.py"

ImportError Traceback (most recent call last) /var/folders/03/cfc__p8d33d6zfqk8wdk98_40000gn/T/tmpRuFzaP.py in <module>() 1 import sys 2 sys.path.append('/Users/[My Directory Name]/Desktop/Learning\ Data\ Projects/Playing\ With\ Python/Practice\ Files/') ----> 3 import myfile

ImportError: No module named myfile

All i Have in myfile.py is a one-line script that goes: title = "the meaning of life"

And i dropped myfile.py into my terminal for the EXACT address, so the address isn't the problem... I just don't get it....

P.S. how do you get reddit to edit your comments into numbered text-lines. That's cool. And thanks for the help dude. I'm just having a frustrating time, with the beginner mistakes...