2

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 http://learnpythonthehardway.org/book/ex45.html. 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"
2
  • 1
    Do you have a script named filename.py in the same directory as script.py? Commented Sep 5, 2013 at 2:41
  • 1
    Instead of literally filename, if your file is saved as something other than "filename" you need to use the actual filename. For example, if your file is called "game.py" you should use import game Commented Sep 5, 2013 at 2:48

2 Answers 2

2

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.

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

Comments

1

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 Comment

that should be sys.path.append("name_of_directory")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.