getting base classes's (super class) _properties tuple
Say I have a fully functional (and more importantly, working) Product will call A. I want to extend this Product's capabilities so I wish to derive another class from it, call it B. No problem, class B(A): ......... now in class B I want to add a new property. Is the a way of getting the base (super) class _properties tuple and just adding the new one to it. Since a tuple is an immutable object I can't do this: _properties=A._properties.append({'id':'RenderStandardHeader', 'type':'int','mode':'w'}) Any thoughts ???? DR
class A: _properties = [ {'a':'A', 'aa':'AA'}, ] class B(A): _properties = [ {'b':'B', 'bb':'BB'}, ] _properties = _properties + A._properties b = B() print b._properties Works for me. -- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People ----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: <zope@zope.org> Sent: Thursday, August 17, 2000 11:30 AM Subject: [Zope] getting base classes's (super class) _properties tuple
Say I have a fully functional (and more importantly, working) Product will call A.
I want to extend this Product's capabilities so I wish to derive another
class from it, call it B.
No problem,
class B(A): .........
now in class B I want to add a new property.
Is the a way of getting the base (super) class _properties tuple and just adding the new one to it. Since a tuple is an immutable object I can't do this: _properties=A._properties.append({'id':'RenderStandardHeader', 'type':'int','mode':'w'})
Any thoughts ????
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
I can't believe it, but I didn't have the last comma ({'b':'B', 'bb':'BB'}, ) and that's what was killing me .....agh BTW, I noticed you are using lists of dictionaries instead of the "standard" tuple of dictionaries. I don't know if there are any consequences to doing this. Anyway, since yours are lists you should be able to to do this: class A: _properties = [ {'a':'A', 'aa':'AA'}, ] class B(A): _properties = [ {'b':'B', 'bb':'BB'}, ] _properties.append(A._properties) not that it realy matters. Thanks, Dan Andy McKay wrote:
class A: _properties = [ {'a':'A', 'aa':'AA'}, ]
class B(A): _properties = [ {'b':'B', 'bb':'BB'}, ] _properties = _properties + A._properties
b = B() print b._properties
Works for me. -- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People
----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: <zope@zope.org> Sent: Thursday, August 17, 2000 11:30 AM Subject: [Zope] getting base classes's (super class) _properties tuple
Say I have a fully functional (and more importantly, working) Product will call A.
I want to extend this Product's capabilities so I wish to derive another
class from it, call it B.
No problem,
class B(A): .........
now in class B I want to add a new property.
Is the a way of getting the base (super) class _properties tuple and just adding the new one to it. Since a tuple is an immutable object I can't do this: _properties=A._properties.append({'id':'RenderStandardHeader', 'type':'int','mode':'w'})
Any thoughts ????
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Aargh isnt that annoying. Gosh you are right im using lists of dictionaries... my Zope code is correct, but that example is wrong. The example still works though... -- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People ----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: "Andy McKay" <AndyM@activestate.com>; <zope@zope.org> Sent: Thursday, August 17, 2000 12:19 PM Subject: Re: [Zope] getting base classes's (super class) _properties tuple
I can't believe it, but I didn't have the last comma ({'b':'B', 'bb':'BB'}, ) and that's what was killing me .....agh
BTW, I noticed you are using lists of dictionaries instead of the "standard" tuple of dictionaries. I don't know if there are any consequences to doing this. Anyway, since yours are lists you should be able to to do this:
class A: _properties = [ {'a':'A', 'aa':'AA'}, ]
class B(A): _properties = [ {'b':'B', 'bb':'BB'}, ] _properties.append(A._properties)
not that it realy matters.
Thanks,
Dan
Andy McKay wrote:
class A: _properties = [ {'a':'A', 'aa':'AA'}, ]
class B(A): _properties = [ {'b':'B', 'bb':'BB'}, ] _properties = _properties + A._properties
b = B() print b._properties
Works for me. -- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People
----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: <zope@zope.org> Sent: Thursday, August 17, 2000 11:30 AM Subject: [Zope] getting base classes's (super class) _properties tuple
Say I have a fully functional (and more importantly, working) Product will call A.
I want to extend this Product's capabilities so I wish to derive another
class from it, call it B.
No problem,
class B(A): .........
now in class B I want to add a new property.
Is the a way of getting the base (super) class _properties tuple and just adding the new one to it. Since a tuple is an immutable object I can't do this: _properties=A._properties.append({'id':'RenderStandardHeader', 'type':'int','mode':'w'})
Any thoughts ????
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
So far so good, Next hurdle, at least the problems have been cut down to hurdles from walls. I have a folderish product say myFolder, in the manage_addMyFolder function I want to create an object of my product B. so I do this: def manage_addmyFolder(self, id, title='', REQUEST=None): """Add a new myFolder object with id *id*. """ ob=myFolder() ob.id=id ob.title=title self._setObject(id, ob) try: user=REQUEST['AUTHENTICATED_USER'] except: user=None ob.manage_addB(id='index_html', title='') <-- if I change this to ob.manage_addDTMLDocument(id='index_html', title='') that works ????? ....... I get the following error: AttributeError: manage_addB Any thoughts, DR
Not to sure there Im afraid. The obvious answer is the manage_addB doesnt exist whereas manage_addDTMLDocument does. -- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People ----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: "Daniel Rusch" <drusch@globalcrossing.com>; <zope@zope.org> Sent: Thursday, August 17, 2000 1:39 PM Subject: [Zope] Creating an object from within another
So far so good,
Next hurdle, at least the problems have been cut down to hurdles from walls.
I have a folderish product say myFolder, in the manage_addMyFolder function I want to create an object of my product B. so I do this:
def manage_addmyFolder(self, id, title='', REQUEST=None): """Add a new myFolder object with id *id*. """ ob=myFolder() ob.id=id ob.title=title self._setObject(id, ob) try: user=REQUEST['AUTHENTICATED_USER'] except: user=None ob.manage_addB(id='index_html', title='') <-- if I change this to ob.manage_addDTMLDocument(id='index_html', title='') that works ????? .......
I get the following error:
AttributeError: manage_addB
Any thoughts,
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Yeah, that's what i thought, but I know it exists cause I can create an object of type B and I copied and pasted the manage_addB part????? For any one else who is reading this: the problem is: I have a product I'll call B. Additionally I have a folderish product I'll call myFolder. What I want to do is when I create a folderish object (a myFolder) in it I want an object B, very similar to when a folder is created you can have a DTMLMethod created. And here is the rub, I am able to have my folderish object create a DTMLMethod instead of an object B. Any thoughts, Dan Andy McKay wrote:
Not to sure there Im afraid. The obvious answer is the manage_addB doesnt exist whereas manage_addDTMLDocument does.
-- Andy McKay, Developer, ActiveState http://www.ActiveState.com Programming for the People
----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: "Daniel Rusch" <drusch@globalcrossing.com>; <zope@zope.org> Sent: Thursday, August 17, 2000 1:39 PM Subject: [Zope] Creating an object from within another
So far so good,
Next hurdle, at least the problems have been cut down to hurdles from walls.
I have a folderish product say myFolder, in the manage_addMyFolder function I want to create an object of my product B. so I do this:
def manage_addmyFolder(self, id, title='', REQUEST=None): """Add a new myFolder object with id *id*. """ ob=myFolder() ob.id=id ob.title=title self._setObject(id, ob) try: user=REQUEST['AUTHENTICATED_USER'] except: user=None ob.manage_addB(id='index_html', title='') <-- if I change this to ob.manage_addDTMLDocument(id='index_html', title='') that works ????? .......
I get the following error:
AttributeError: manage_addB
Any thoughts,
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Andy McKay -
Daniel Rusch