module naming?

Michal Wallace (sabren) sabren at manifestation.com
Mon Apr 17 02:39:00 CEST 2000


Hey All,

 I've got a package I'm getting ready to share named zdc, and it has
some submodules: zdc.Record, zdc.Field, zdc.IdxDict.. Each one of
those contains a class with the corresponding name: zdc.Record.Record,
zdc.Field.Field, zdc.IdxDict.IdxDict.

  I've read the essay on built-in package support,
( http://www.python.org/doc/essays/packages.html ), but I just don't like
the notion of having to say:

   import zdc.Record
   rec = zdc.Record.Record()


when this looks so much nicer:

   import zdc
   rec = zdc.Record()


Now, I know I can do this by putting all my classes in zdc.py, but I
think it's a lot cleaner to keep my classes in their own files.

I also don't want to do "from zdc import *" because people who use my
modules will probably only want one of the classes at a time. Or at
least I will. :)

The other approach I'm considering is changing my module names to
lowercase, and doing something like this in zdc/__init__.py :


def Record(dbc, table):
   import zdc.record, zdc
   zdc.Record = zdc.record.Record
   return zdc.record.Record(dbc, table)


.. That way, the first time you call zdc.Record() it imports
zdc.record, and every time after that, it just initializes a
zdc.record.Record object... 

Is there a better way to do this?

Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------





More information about the Python-list mailing list