importing question ?
Cliff Wells
LogiplexSoftware at earthlink.net
Fri Nov 29 20:40:07 EST 2002
On Fri, 2002-11-29 at 16:42, Kenny Tilton wrote:
> Kenny Tilton wrote:
> >
> >> 'from classes import *' brings all the toplevel objects in classes
> >> into your local namespace, so you can access them just through the
> >> name. Generally, though, I think this is considered bad practice, as
> >> it could create overlaps.
> >
> >
> > I just ran into this and I do not like it, because I have what I
> > consider one little subsystem (Cells) but I have it spread over ten
> > source files.
>
> I just saw the option to:
>
> from <package> import *
>
> along with listing all modules in an __all__ definition in the __init__
> file in the package directory. hope eternal. but it seems I then have to
> qualify any reference with the module name (which I think I grok--it is
> importing everything into the current namespace in go (nice) but then
> leaves them compartmented by module when it does so (not what I wanted,
> viz, a flat namespace for the package).
Would the following sort of arrangement work for you?
# --- file f1.py ---
def fun1():
print "f1"
# --- file f2.py ---
def fun2():
print "f2"
# --- file f3.py ---
def fun3():
print "f3"
# --- file f.py ---
from f1 import fun1
from f2 import fun2
from f3 import fun3
# --- file main.py ---
import f
f.fun1()
f.fun2()
f.fun3()
Just use an intermediary module to import the other files into (this
could be the __init__.py file in a package directory).
> --
>
> kenny tilton
> clinisys, inc
> ---------------------------------------------------------------
> ""Well, I've wrestled with reality for thirty-five years, Doctor,
> and I'm happy to state I finally won out over it.""
> Elwood P. Dowd
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20021129/9e2805e6/attachment.sig>
More information about the Python-list
mailing list