I have such a simple module's structure:
mod1/
__init__.py
clsOne.py
clsN.py
Where code looks like this:
__init__.py:
# module init
from clsOne import MyFirstCLass
from clsN import NThCLass
clshnd = MyFirstClass()
...
nhnd = NThClass()
clsOne.py:
class MyFirstClass( object ):
pass
clsN.py:
classNThClass( object ):
pass
Now I use them as follows:
Way #1)
from mod1.clsOne import MyFirstClass
or:
Way #2)
from mod1 import clshnd
Is it possible to import name clshnd
but in such a way that other handlers (i.e. nhnd
) are initialized only on demand (when explicitelly imported)?
Zbigniew
You just put the relevant code into a separate module.
mod1/
__init__.py
clsOne.py
clsN.py
foo.py
And then in foo.py
:
from clsOne import MyFirstCLass
from clsN import NThCLass
clshnd = MyFirstClass()
...
nhnd = NThClass()
精彩评论