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 <[EMAIL PROTECTED]> 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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to