Point well taken, and indeed a brilliant solution. Thank you I V for
demonstrating so clearly.
I V wrote:
> On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote:
> > A misuse of inheritance eh? Inheritance, like other language features,
> > is merely a tool. I happen to be using this tool to
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > I'm working with a team that's doing social modeling, and for example,
> > I need to model workers that at some point in the program may or may
> > not also become employers. Now, I want the workers to take on all
> > behaviors and attributes o
[EMAIL PROTECTED] wrote:
> How can an object replace itself using its own method? See the
> following code
[code deleted]
At the risk of creating totally incomprehensible and
unmaintainable code, you need two things:
First, you can change the class of any new style
object by assigning to the __
Hi Bruno :)
On 2006-06-27 10:30, Bruno Desthuilliers wrote:
> FWIW, a good part of the canonical design patterns are mostly workaround
> the lack of flexibility in languages like C++ and Java.
May be, but that doesn't exclude that some patterns are also
useful in Python. :-)
> The Strategy
> pat
Fredrik Lundh wrote:
> Bruno Desthuilliers wrote:
>
>
>>As a matter of fact, in Python, the class is an attribute of an object.
>
>
> except when it isn't.
Which are the cases where it isn't ?
>
>>>def add_role(self, role_class):
>>> self.roles.append(role_class(self))
>>
>>And here you cr
Bruno Desthuilliers wrote:
> As a matter of fact, in Python, the class is an attribute of an object.
except when it isn't.
>> def add_role(self, role_class):
>>self.roles.append(role_class(self))
>
> And here you create a circular reference between object and roles...
and ? Python has a ga
I V wrote:
> On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote:
>
>>A misuse of inheritance eh? Inheritance, like other language features,
>>is merely a tool. I happen to be using this tool to have my virtual
>>persons change roles at different points in their lifetime, as many
>>real peop
Maric Michaud wrote:
> Le lundi 26 juin 2006 22:37, [EMAIL PROTECTED] a écrit :
>
>>Won't work because there will be employers that aren't workers.
>>And yes, only some workers will become employers, but also only some
>>employers will also be workers (at some point in program). Let me be
>>more c
On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote:
> A misuse of inheritance eh? Inheritance, like other language features,
> is merely a tool. I happen to be using this tool to have my virtual
> persons change roles at different points in their lifetime, as many
> real people tend to do. T
[EMAIL PROTECTED] wrote:
> I'm working with a team that's doing social modeling, and for example,
> I need to model workers that at some point in the program may or may
> not also become employers. Now, I want the workers to take on all
> behaviors and attributes of an employer in addition to thei
Bruno Desthuilliers wrote:
(snip)
> >
> > It is very important that both should maintain attribute values,
> > regardless of whether they take on new "roles".
>
> Seems obvious. But just a question, BTW: do workers and employers share
> the same attributes ? And if not, how do you intend to initia
Maric Michaud wrote:
> Le lundi 26 juin 2006 22:37, [EMAIL PROTECTED] a écrit :
> > Won't work because there will be employers that aren't workers.
> > And yes, only some workers will become employers, but also only some
> > employers will also be workers (at some point in program). Let me be
> >
Le lundi 26 juin 2006 22:37, [EMAIL PROTECTED] a écrit :
> Won't work because there will be employers that aren't workers.
> And yes, only some workers will become employers, but also only some
> employers will also be workers (at some point in program). Let me be
> more clear:
>
> workers
> --> su
[EMAIL PROTECTED] a écrit :
> Bruno Desthuilliers wrote:
>
>>[EMAIL PROTECTED] a écrit :
>>
>>>Bruno Desthuilliers wrote:
>>
>>(snip)
>>
Instead of exposing problems with your solution, you may want to expose
the real use case ?
>>>
>>>
>>>I'm working with a team that's doing social modeli
Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] a écrit :
> > Bruno Desthuilliers wrote:
> (snip)
> >>
> >>Instead of exposing problems with your solution, you may want to expose
> >>the real use case ?
> >
> >
> > I'm working with a team that's doing social modeling, and for example,
> > I need to
[EMAIL PROTECTED] a écrit :
> Bruno Desthuilliers wrote:
(snip)
>>
>>Instead of exposing problems with your solution, you may want to expose
>>the real use case ?
>
>
> I'm working with a team that's doing social modeling, and for example,
> I need to model workers that at some point in the progr
[EMAIL PROTECTED] wrote:
> Maric Michaud wrote:
>
(snip)
>>This doesn't work in most cases (with new style classes), better recreat a
>>type which inherit from Class and Mixin, or Class.__dict__ with
>>Mixin.__dict__.
>
>
> What doesn't work exactly? The whole purpose of the mixin is to add
> f
Maric Michaud wrote:
...
> > def MixInto(Class, Mixin):
> > if Mixin not in Class.__bases__:
> > Class.__bases__ += (Mixin,)
>
> This doesn't work in most cases (with new style classes), better recreat a
> type which inherit from Class and Mixin, or Class.__dict__ with
> Mixin.__dict__
Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] wrote:
> > How can an object replace itself using its own method?
>
> AFAIK, It can't (but I can be wrong - some guru around ?).
>
> > ...
>
> FWIW:
> Python 2.4.3 (#1, Jun 3 2006, 17:26:11)
> [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] o
Maric Michaud wrote:
> Le lundi 26 juin 2006 17:57, [EMAIL PROTECTED] a écrit :
> > How can an object replace itself using its own method? See the
> > following code:
> >
> > class Mixin:
> > def mixin(object, *classes):
> > NewClass = type('Mixin', (object.__class__,) + classes, {})
>
[EMAIL PROTECTED] wrote:
> How can an object replace itself using its own method?
AFAIK, It can't (but I can be wrong - some guru around ?).
> See the
> following code:
>
> class Mixin:
> def mixin(object, *classes):
> NewClass = type('Mixin', (object.__class__,) + classes, {})
>
Le lundi 26 juin 2006 17:57, [EMAIL PROTECTED] a écrit :
> How can an object replace itself using its own method? See the
> following code:
>
> class Mixin:
> def mixin(object, *classes):
> NewClass = type('Mixin', (object.__class__,) + classes, {})
> newobj = NewClass()
>
How can an object replace itself using its own method? See the
following code:
class Mixin:
def mixin(object, *classes):
NewClass = type('Mixin', (object.__class__,) + classes, {})
newobj = NewClass()
newobj.__dict__.update(object.__dict__)
return newobj
def is
23 matches
Mail list logo