[Tutor] Importing from directories below yourself...
Kent Johnson
kent37 at tds.net
Tue Jun 21 17:37:17 CEST 2005
lawrence wang wrote:
> Say I have a directory tree like this:
>
> foo
> - bar
> -- quux.py
> - baz
> -- glonk.py
>
>>From within glonk.py, how do I import quux.py? I've tried going to
> foo, running baz/glonk.py, and using "from bar import quux", but this
> doesn't seem to work.
You need a file named __init__.py in bar/. The file can be empty; it is a marker that tells Python to treat bar/ as a package.
You will also need __init__.py in baz/ if you want to be able to import glonk from another module.
See http://docs.python.org/tut/node8.html#SECTION008400000000000000000
Kent
More information about the Tutor
mailing list