Organizing Python Code

Greg Ewing see at my.signature
Wed Oct 4 19:56:01 EDT 2000


Russell Wallace wrote, concerning "import *":
> 
> What problems do you see it causing?

In my experience, the main thing you lose is the ability
to easily track down which module a given identifier is
coming from. This can be quite important when working on
someone else's code, or your own code some time later.

Recently I had occasion to work on a Borland Pascal
program written by someone else, consisting of a few
dozen source files spread over several directories.
I found myself wishing that Borland Pascal had a more
explicit import mechanism than just "uses modulename".

It's certainly more work to maintain an explicit import
list, but I find that it pays off in the long run.

Another alternative is to just import the module name
and always use qualified references. That gives you
most of the same benefits for less work, at the expense
of a slight runtime penalty.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list