how to reuse class deinitions?

Scott David Daniels scott.daniels at acm.org
Sun Oct 1 18:48:48 EDT 2006


sam wrote:
> pretty straightforward question here, i think. i'm experimenting with
> classes and have written a File class that looks like it's worth
> keeping for future use. however, i cannot work out where to put it for
> this purpose or how to get it in.

What I do:

For each new major version of python, in .../site-packages I make a
directory "sdd" (my initials).  In it I put an empty file named
"__init__.py".  When I have things I want to reuse, I put them in
files named things like ".../site-packages/sdd/goodidea.py", and
I get use of them in python programs like:

     from sdd.goodidea import File
     ...
     <code that uses File>
     ...

or (actually my current style):
     from sdd import goodidea
     ...
     <code that uses goodidea.File>
     ...

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list