Re: parent-child object design question

2007-02-04 Thread Steven D'Aprano
On Fri, 02 Feb 2007 13:53:21 -0800, manstey wrote: Hi, There was a mistake above, and then I'll explain what we're doing: insCacheClass = CacheClass(oref) insCacheProperty = CacheProperty(insOref,'Chapter') should have been insCacheClass = CacheClass(oref) insCacheProperty =

Re: parent-child object design question

2007-02-02 Thread manstey
Hi, There was a mistake above, and then I'll explain what we're doing: insCacheClass = CacheClass(oref) insCacheProperty = CacheProperty(insOref,'Chapter') should have been insCacheClass = CacheClass(oref) insCacheProperty = CacheProperty(insCacheClass ,'Chapter') Now, to answer some

Re: parent-child object design question

2007-01-31 Thread Ben Finney
Steven D'Aprano [EMAIL PROTECTED] writes: def _accumulate_properties(self, properties): self.properties = [] Probably better to put that in the __init__ method, otherwise if somebody runs instance._accumulate_properties(...) again, it will have the side-effect of

Re: parent-child object design question

2007-01-31 Thread manstey
Thanks for your input. Here is my next version, which works very well, but for one problem I explain below: class CacheProperty(object): def __init__(self, insCacheClass, name): self.Name = name self._bind_to_parent(insCacheClass) self.__parent = insCacheClass

Re: parent-child object design question

2007-01-31 Thread Ben Finney
manstey [EMAIL PROTECTED] writes: However, the problem is now that I can also write: insOref.Chapter=67 but we want to disallow this, as insOref.Chapter must remain = insProperty Then don't do that. Python allows any name to be reassigned to any value, with the attitude of we're all

Re: parent-child object design question

2007-01-31 Thread Steven D'Aprano
On Wed, 31 Jan 2007 20:15:44 +1100, Ben Finney wrote: Steven D'Aprano [EMAIL PROTECTED] writes: def _accumulate_properties(self, properties): self.properties = [] Probably better to put that in the __init__ method, otherwise if somebody runs

Re: parent-child object design question

2007-01-31 Thread Steven D'Aprano
On Wed, 31 Jan 2007 15:09:29 -0800, manstey wrote: Thanks for your input. Here is my next version, which works very well, but for one problem I explain below: class CacheProperty(object): def __init__(self, insCacheClass, name): self.Name = name

Re: parent-child object design question

2007-01-30 Thread manstey
Hi Ben, Could I also do something like the following? What does it mean to store the parent class as a private variable in the child class? class CacheProperty(object): def __init__(self, obj, parent, properties=None): self.__data = obj self._parent = parent

Re: parent-child object design question

2007-01-30 Thread Ben Finney
manstey [EMAIL PROTECTED] writes: Could I also do something like the following? I can't immediately see a problem with the code you posted. Does it do what you want it to do? What does it mean to store the parent class as a private variable in the child class? I don't understand this

Re: parent-child object design question

2007-01-30 Thread Steven D'Aprano
On Tue, 30 Jan 2007 21:15:53 -0800, manstey wrote: Hi Ben, Could I also do something like the following? What does it mean to store the parent class as a private variable in the child class? What it means is that references to self.__data (note the TWO leading underscores) in your code

parent-child object design question

2007-01-29 Thread manstey
Hi, I am having trouble designing my classes. I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj): self.__data = obj def __getattr__(self, attr): return getattr(self.__data, attr) The second

Re: parent-child object design question

2007-01-29 Thread Ben Finney
manstey [EMAIL PROTECTED] writes: I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj): self.__data = obj def __getattr__(self, attr): return getattr(self.__data, attr) I presume the 'obj'