Reputation: 2576
newbie Python question, 2.7.2 on Windows XP
I saved a one-line hello.py file [print "hello there"] in the current directory.
At the command prompt I use import to run the command
>>> import hello
hello there
ok - that's fine.
But what do you type if hello.py were in a subfolder of the current directory called "tempFolder"?
Upvotes: 1
Views: 68
Reputation: 18870
The module is searched in Python's module search path.
You have two solutions:
Make the folder tempFolder
be a python package: Add a file named __init__.py
in the folder tempFolder
Add the folder tempFolder
to the PYTHONPATH
Upvotes: 1
Reputation: 8421
Assuming this is your directory structure:
currentdir
/tempFolder
hello.py
You should have a __init__.py
in your directory of import.
So it should look like:
currentdir
/tempFolder
__init__.py
hello.py
Note: the __init__.py
could be blank. There is no harm in that.
Check the official documentation for more information on this
Upvotes: 2