I’m kinda new to Python, so i’m still lost in the whole namespace thing.
I’ve created a package, with the init file in it and also a classname.py file, with the class, obviously.
For instance:
from parachute import container, emitter
I tried to instance the class Container directly, but it gave me an error, so i had to instance it as container.Container(). How can i avoid doing this?
Basically, what i want to do is to import a class from a package and avoid typing the package name and/or the file name.
Thanks in advance, and please let me know if the question isn’t clear enough.
UPDATE
The structure i have is:
– parachute
— init.py
-- container.py
Serves as a controller, i'd say, instancing, calling and glueing all the other parts together.
-- sparkles.py
Has two classes: Sparkle and Sparkles. Sparkle is a single element, with only one property so far, and Sparkles serves as a collection. Sparkles() belongs to the Emitter, and Sparkle() belongs to Sparkles().
-- emitter.py
Emitter could be seen as the user entity. It has a name and an uid, it belongs to a Container and the Container belongs to it.
Now, from outside the package i’m calling Container and passing some arguments, and the Container instances and distributes the arguments as it needs.
I have the impression that this isn’t the best way to do what i need to do, which is: Create a collection of sparkles, owned by the emitter.
Don’t put the class in it’s own file. Put
ContainerandEmitterdirectly inparachute.py.You can then do
or
This essentially boils down to “Python isn’t Java so for best results, don’t treat it like it is” 😉