[Tutor] Mixing in and Mixing out classes in python

Kent Johnson kent37 at tds.net
Fri Aug 1 02:29:12 CEST 2008

On Thu, Jul 31, 2008 at 8:09 PM, Tomaz Bevec <tomazbevec at yahoo.com> wrote:
> Thanks for your reply Alan,
> I am partially asking out of interest, but I also have a potential application.
> I'm working on a simulation of cellular growth patterns (basically cell instances interacting stochastically on a lattice).  Anyway, there are many different cell "behaviors" that I have to simulate, and cells can potentially gain and lose these "behaviors" over the course of the simulation.  It would be too much to put every behavior function in the cell class, so I'm writing each behavior as a mixin and mixing it in (and initializing it) when necessary or when biological function is gained by the cells.

Perhaps you could keep the behaviors in a dictionary? You could
override __getattr__() in the cell class to look up attributes whose
names start with 'behavior' in the dict.


More information about the Tutor mailing list