lambda closure question

Mike Meyer mwm at mired.org
Mon Feb 21 00:01:26 EST 2005


"Carl Banks" <invalidemail at aerojockey.com> writes:

> Say you have a suite of functions, all of which are called by some main
> function and each other, and all of which need to access a lot of the
> same data.  The best, most straightforward way to do it is to have the
> common data be a local variable of the main function, and nest the
> suite inside it.  The other way to do it, passing around a common data
> structure, add complexity and hurts performance.

The third way to do it is to make the thing a class. Make all the
functions methods of the class, and all the data instance
variables. You may well want to make the main function the __call__
method of the class. In an OO environment, this may be a better, more
straightforward way than nesting fnctions.

See <URL:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 > for an
example of this.

        <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