[Tutor] Understanding (Complex) Modules

Wayne Watson sierra_mtnview at sbcglobal.net
Thu Mar 4 02:24:35 CET 2010


First a little preamble before my questions.

Most of my work in Python has required modifying a program that uses 
modules that were imported by the original program. I've made some use 
of modules on a command line like math, and have used the idea of a 
qualifier.  On occasion, I've used examples from matplotlib that 
required from matplotlib.image import AxesImage. Further, I've created 
some simple classes, and produced  objects with them. No use of 
inheritance though.  So far so good.  In a few places, it is said 
modules are objects. I'm slightly puzzled by that, but in some way it 
seems reasonable from the standpoint of period notation. So far I have 
not created a module.

In Lutz's and Ascher's Learning Python, ed. 2, chap. 16, they describe 
the following example, among others:

module2.py as

print "starting to load ..."
import sys
def func(): pass
class klass: pass
print "done loading."

Their description of its use is quite readable.  It shows that there is 
some more to a module than a list of defs, for example.

Here comes the questions. Recently I began to use matplotlib, scipy, and 
pylab, mostly matplotlib. I've ground out a few useful pieces of code, 
but I'm fairly baffled by the imports required to get at various 
elements, of say, matplotlib (MPL).  Some of the MPL examples use of 
imports make sense, but how the writer pulled in the necessary elements 
is not.  How does one go about understanding the capabilities of such 
modules? MPL seems to have a lot of lower level components. Some of them 
are laid out over numerous pages as in the form of a, say, English 
language, description. How does one decipher this stuff.  For example, 
open the module in an editor and start looking at the organization? I 
thinkthe so called MPL guide ins 900 pages long. Even the numpy guide 
(reference?), I believe borders on 1000 pages. There must be some way to 
untangle these complex modules, I would think. Some of the tutorials 
seem nothing more than a template to follow for a particular problem.  
So far, looking at the plentiful number of examples of MPL, and probably 
some of the other modules mentioned above have not provided a lot of 
insight.

  Is there some relationship between modules and objects that I'm not 
seeing that could be of value?




-- 
            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

                Stop the illegal killing of dolphins and porpoises.
                      <http://www.takepart.com/thecove>
               Wrest the control of the world's fisheries from Japan.

                     Web Page:<www.speckledwithstars.net/>



More information about the Tutor mailing list