I'm working on Learn python the hard way and am not a very experienced programmer and I have searched on Stackoverflow and other programming websites but I have not found the answer to my question. Well anyway my question is how do you import files into another file in python what I have seen is that many people have answered this by saying that you should just put import filename but when I do this I get the error Traceback (most recent call last): File "source.py", line 1, in <module> import one ImportError: No module named filename so how do I import a file without getting this error. if anybody would like to know where to go to see why I'm asking question go to . I'm also using a chromebook so I have an app named source lair instead of the traditional python software, so if anybody has a chromebook or chromeos computer please give me suggestions as to if this is a good app and if there's a better app. ps: you can download the app from the chrome store on any operating system.
print "thanks" 22 Answers
just put the file "filename.py" into the same dir as source.py if you sure you have created a file named "filename.py". Then import filename in source.py will work.
python looks for modules in sys.path. in python
import sys
print sys.path ... it will print the list of directories where it look for modules
you can add a directory in sys.path
sys.append("name_of_directory")
or you can set PYTHONPATH environment variable for directory.
1