Splitting up classes between files

Darrell news at dorb.com
Fri Dec 31 10:40:53 EST 1999


Using import a1,a2,... in a.py to avoid making the user do it, is tricky.

Your users will now have to write a.a1.xxx
If they had the import a1 they could just say a1.xxx

You could try this in a.py.
    from a1 import *
    from a2 import *

Now they can say a.xxx, but they might get xxx from a2.
from xxx import * is considered unhealthy and should be used with care.

You could stay with the import a1,a2,... in a.py. Then write an interface to
this collection of modules in a.py. Remember that a function in a.py can
return an instance from a1.py and your user doesn't need an "import a1".


--
--Darrell
"Roy Smith" <roy at endeavor.med.nyu.edu> wrote in message
news:roy-E337E8.09101731121999 at netnews.nyu.edu...
> I've got a top-level class, a, and a bunch of sub-classes, a1, a2, a3,
etc.  To
> make it easier to manage the code, I'd like to put each in a separate
file, but
> still have the user be able to import the whole bunch with a single
import, i.e.
> not have to do "import a, a1, a2, a3, etc".
>
> Can I just put "import a1, a2, a3, etc" in the bottom of my "a.py" file?
It
> seems like it should work fine, but are there any hidden gotchas?
>






More information about the Python-list mailing list