Question on making names visible in packages

Kenneth McDonald kmmcdonald at wisc.edu
Sun Mar 14 15:03:29 EST 2004


This will have an easy answer, no doubt, unfortunately I can't
think of it...

I'm writing a package which will have a number of classes. I'd
like to split them amongst different files within the package.
However, I'd also like the package user to be able to say:

	import Package

and then to use the classes as 

	Package.Class1, Package.Class2, etc.

However, I'm only able to get this behavior when I leave the
class definitions in the __init__.py file. When in other files,
they of course have to be referenced as :

	Package.filename.Class1

Is there some way of making the names visible at the top level
of the module, to mask the fact that they are split amongst
different files within the package? The split reflects a
logical organization of the code from the point of view of
the designer of the package, but not from the user, and
so I don't want the user to necessarily be aware of the
file organization. (If they want to be, hey, that's fine...)


Thanks,
Ken McDonald



More information about the Python-list mailing list