__init__.py

km srikrishnamohan at gmail.com
Tue Nov 14 06:40:58 EST 2006


Hi,

I have a structure like this :
foo/__init__.py
foo/bar/__init__.py
foo/bar/firstmodule.py
foo/abc/__init__.py
foo/abc/secondmodule.py

now i have some variables (paths to data files) common, to be used in
first module
and second modules respectively.
can i set those variables in foo/__init__.py so that i can access them by
foo.mypath1 in first and second submodule class definitions?  if not
anyother way out ?
regards,
 KM

On 11/14/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
>
> km wrote:
>
> > what is the use of __init__.py file in a module dir ?
>
> it tells Python that the directory is a package directory.  if you have
>
>      mydir/foo/__init__.py
>      mydir/foo/module.py
>
> and mydir is on the path, you can do "import foo.module" or "from foo
> import module".  if you remove the __init__.py file, Python will no
> longer look for submodules inside that directory.
>
> > Is it used to initialize variables  that could be shared across sub
> > modules  if set in __init__.py at root dir  of module ?
>
> it's usually empty, or used to export selected portions of the package
> under more convenient names.  given the example above, the contents of
> the __init__ module can be accessed via:
>
>      import foo
>
> </F>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061114/36755fe7/attachment.html>


More information about the Python-list mailing list