P: n/a
|
hi,
i have written a small project for myself all in seperate classes and
each of the classes lives in a seperate file. now i am looking for an
import structure something like import wx, and then have access to all
my classes just like wx.Button or wx.BoxSizer etc.
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.
thank you in advance | |
Share this Question
P: n/a
|
On Apr 30, 9:56 am, spohle <spo...@gmail.comwrote:
hi,
i have written a small project for myself all in seperate classes and
each of the classes lives in a seperate file. now i am looking for an
import structure something like import wx, and then have access to all
my classes just like wx.Button or wx.BoxSizer etc.
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.
thank you in advance
If it really is a small project, consider just putting all the classes
into a single module, say spohlePkg.py. Then your users would import
this module using "import spohlePkg", and would access the classes as
"spohlePkg.ClassA", "spohlePkg.ClassB", etc.
-- Paul | |
P: n/a
|
On Apr 30, 8:00 am, Paul McGuire <p...@austin.rr.comwrote:
On Apr 30, 9:56 am, spohle <spo...@gmail.comwrote:
hi,
i have written a small project for myself all in seperate classes and
each of the classes lives in a seperate file. now i am looking for an
import structure something like import wx, and then have access to all
my classes just like wx.Button or wx.BoxSizer etc.
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.
thank you in advance
If it really is a small project, consider just putting all the classes
into a single module, say spohlePkg.py. Then your users would import
this module using "import spohlePkg", and would access the classes as
"spohlePkg.ClassA", "spohlePkg.ClassB", etc.
-- Paul
yeah i had that, but my classes grew really fast and i decided to
split them up. but you're right that in one file that would solve my
problem. still hoping to find a way for the seperate files. | |
P: n/a
|
On Apr 30, 8:16 am, "Hamilton, William " <wham...@entergy.comwrote:
-----Original Message-----
From: python-list-bounces+whamil1=entergy....@python.org
[mailto:python-
list-bounces+whamil1=entergy....@python.org] On Behalf Of spohle
Sent: Monday, April 30, 2007 10:03 AM
To: python-l...@python.org
Subject: Re: import structures
On Apr 30, 8:00 am, Paul McGuire <p...@austin.rr.comwrote:
On Apr 30, 9:56 am, spohle <spo...@gmail.comwrote:
hi,
i have written a small project for myself all in seperate classes
and
each of the classes lives in a seperate file. now i am looking for
an
import structure something like import wx, and then have access to
all
my classes just like wx.Button or wx.BoxSizer etc.
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.
thank you in advance
If it really is a small project, consider just putting all the
classes
into a single module, say spohlePkg.py. Then your users would
import
this module using "import spohlePkg", and would access the classes
as
"spohlePkg.ClassA", "spohlePkg.ClassB", etc.
-- Paul
yeah i had that, but my classes grew really fast and i decided to
split them up. but you're right that in one file that would solve my
problem. still hoping to find a way for the seperate files.
If you've got modules a, b, and c, you can create a wrapper module d
that imports from each of those.
from a import *
from b import *
from c import *
Then, import d and use it as the module name. So if a had a SomeThing
class, you could do this:
import d
x = d.SomeThing()
---
-Bill Hamilton
that doesn't seem to work for me. the from a import * will only give
me a not d.a | |
P: n/a
|
spohle <sp****@gmail.comwrote:
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. | | This discussion thread is closed Replies have been disabled for this discussion. | | Question stats - viewed: 1408
- replies: 4
- date asked: Apr 30 '07
|