Importing modules

Mike Meyer mwm at mired.org
Thu May 12 01:15:25 EDT 2005


qwweeeit at yahoo.it writes:

> A part the fact that I have not understood the "real" difference
> between import and from ... import (or also from... import *), is it
> possible to re-build the application in only one chunck?
> This is only to better understand the application's structure, in order
> to implement a flow chart tool.

"import foo" creates foo in the current namespace. It'll be a module.

"from foo import bar" creates bar from the foo module in the current
namespace. It's type will be the same as it is in foo. Note that
assigning to bar in the current namespace after doing this import
*will not* change bar in foo.

> I have already developed a cross reference tool and I applied it to
> PySol (solitary card games). PySol is made up of almost 100 modules for
> a total of almost 30000 lines.
> To understand a program, however, you need also a flow chart...

*You* may need a flowchart. Lots of people don't. The last time I had
to document a program graphically, I used something other than
flowcharts (I've since forgotten the name, but could provide examples
on demand). Such tools are really only useful for describing a single
function. To understand the relationship between
functions/methods/etc., you really need other tools. UML is probably
the most used such tool in the OO world.

To understand a program, you need to understand the communications
channels between the components. Mashing all the components together
into one namespace destroys the very information you need to properly
understand the program. BON is a nice format for documenting such
things, but it's really aimed at a more pure OO environment than
Python provides.

       <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list