How to write good Python objects?

John Ladasky ladasky at my-deja.com
Thu Oct 23 21:15:09 EDT 2003


Hi, folks,

At the beginning of 2003, I was a frustrated computer user, and lapsed
programmer, with problems to solve that screamed for programming. 
Thanks to the Python language and community, I am a programmer once
again.

My earlier solicitation to the computer world is here:

http://groups.google.com/groups?selm=c09b237b.0302060136.5683054e%40posting.google.com

Anyway, I've been busy with Python for several months now.  I'm an old
procedural guy.  I had never written code in an object-oriented
language before.  I'm starting to get the hang of it, and to see its
advantages, but I'm still struggling.  I think that I have issues with
both OOP in general, and with Python in particular.

I have written one nice, self-contained object that contained a DNA
sequence, and various functions to manipulate the data therein.  My
wxPython GUI objects, in contrast, are in a state of constant flux. 
Rather than importing and reusing a piece of code, I find myself
copying the code into my new program and playing with it, just a bit. 
I'm starting to believe that writing a good GUI object, one that you
can really reuse, is actually quite hard.  Yes, I know that you can
derive a new object that overrides properties of your old object. 
Should I find myself doing this for every object that I write?

One other thing -- I would like to be able to include a statement in
my program to the effect of: "from my_package import
my_function_or_class".  Python seems to look for .pyc files in the
/Lib folder.  By placing a .py file in /Lib, I got it to compile, and
to be recognized by an import statement.  Is this the right way for
users to package their own code?  It seems kludgy to me.

If it matters (it shouldn't), I'm running Python 2.2.2 on Win2000 Pro.

Thanks for your advice!

--
John J. Ladasky Jr., Ph.D.
Department of Biology
Johns Hopkins University
Baltimore MD 21218
USA
Earth




More information about the Python-list mailing list