Re: import structures



spohle <spohle@xxxxxxxxx> wrote:

as of now i have a __init__.py file in the directory with:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

but i still have to import each class by it's own. im really looking
for something like import wx
and then get all my access right away under this new namespace.

You just need to make your __init__.py import anything you want to be
available directly under the package.

So if the folder pkg contains __init__.py, class1.py, class2.py all you
have to do is make pkg/__init__.py contain something like:

from class1 import Class1
from class2 import Class2

And then when using the package you can do:

from pkg import Class1, Class2

or

import pkg
...
something = pkg.Class1()

as you prefer.
.



Relevant Pages

  • question about package
    ... would you please explain how to put classes in package and to use them. ... Class1 and Class2 in the ... symbol: class Class2 ... Class2 compiled ok, but not Class1. ...
    (comp.lang.java.help)
  • Re: whats the general way of separating classes?
    ... class1 and class2 in each other module of your program? ... Felipe's example is a little confusing because he uses the same name ... import package ...
    (comp.lang.python)
  • Re: UML und java
    ... Hat bei dieser UML Darstellung Class2 auch eine Variable von Class1? ... Komposition und Aggregation in Java wirklich kein Unterschied? ... private Wort wort; ...
    (de.comp.lang.java)
  • UML und java
    ... Hat bei dieser UML Darstellung Class2 auch eine Variable von Class1? ... Komposition und Aggregation in Java wirklich kein Unterschied? ... Angenommen ich möchte einen Satz objektorientiert darstellen. ...
    (de.comp.lang.java)
  • Re: Subclassing VBA/VB6/.Net
    ... You'd want Instancing of the 2nd class ... If these classes are in a standard EXE ... In Class1, you'd create an instance of Class2 in the Initialize event. ...
    (microsoft.public.vb.general.discussion)