On Wed, 27 Dec 2006 23:27:08 +0100, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>In <[EMAIL PROTECTED]>, Osiris wrote: > >> I have an array (I come from C) of identical objects, called sections. >> These sections have some feature, say a length, measured in mm, which >> is calculated by a method A_length of the instantiation of the >> Section's class. >> Only, two elements in the array (or list ?) have a length that must be >> calculated according to a totally different procedure, a different >> function or method. > >Is this something that the instances of section "know" or is some external >"knowledge" needed to identify those special objects? the sections know, beforehand. I can write the method NOW. > >> After calculation of ALL the lengths, they must be added together and >> output. >> The calculation procedure screams for a FOR or a WHILE loop allong the >> list of sections, only those two sections mentioned make life >> difficult. > >Sounds like something like ``sum(section.length() for section in sections)``. > >Your description is a bit vague. Where and how do you start to treat the >objects different. I create all sections, also the differeent one. I know all along which is differeent. > Is it possible to decide at instantiation time to >create a `Section` object or a `SpecialSection` object? How much YES >different is the calculation? rather al lot. > Do you need two separate classes or just >one with a flag or maybe a function as argument to the `__init__()` is differenter than that.. >method? Are you writing the `Section` class(es) just for this >calculation or do they contain other behavior too? > They have a lot of other behavior too... >Ciao, > Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list