[Newbie:]Importing modules from different files

gtnorton at my-deja.com gtnorton at my-deja.com
Thu Sep 9 12:17:05 EDT 1999


In article <7r8g0i$mpf$1 at news1.tele.dk>,
  "Jesper Hertel" <jh at cddk.dk> wrote:
> You have to put a file called "__init__.py" into the new directory.
This
> makes the directory a Python package.
>
> Let's say the name of the new directory is "spam". When you use
"import
> spam", you import the contents of the __init__.py file as a module. If
you
> put a file, e.g. "mymodule.py", inside the spam directory, you can
import
> this module using "import spam.mymodule" or "from spam import
mymodule" -
> but again, this only works if you created the (possibly empty) file
> "__init__.py" in the "spam" directory.
>
> Hope this helps.
>
> Jesper Hertel
>
                                  Thanks Jesper.I could not find any
answer to this in "Learning Python".God, ship the PythonWin book!!!!!!!


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list