[Zope] accessing object from a list constructed in __init__.py
kevin7kal
plone at kevinkal.com
Sun Jul 23 10:36:30 EDT 2006
I've changed my code a bit, adding the docstring, Persistent to all
classes and
__allow_access_to_unprotected_attributes__ = 1 to all classes. Still, I
recieve the same error.
I have changed the code so _attribute1a is a single instance of class1
instead of a list of containing multiple instances of class1 and I can
access the attributes of the object without issue.
Are the objects automatically unwrapped when added to a list? is there
a way around this?
I can send the code again if need be.
so here is the code again, this time with only the single object in
attribute1a.
--myClass.py--
import Acquisition
from persistent import Persistent
class class1(Acquisition.Explicit,Persistent):
''' a simple class with some attributes and methods'''
__allow_access_to_unprotected_attributes__ = 1
attribute1 = 'attribute 1'
attribute2 = 'attribute 2'
_number = ''
def __init__(self,number2):
'''simple init for the class'''
self._number=number2*3
def method1(self):
'''return a string methd1'''
mthd1 = 'methd1'
return mthd1
def method2(self):
''' return a string methd2'''
mthd2 = 'method2'
return mthd2
def _get_number(self):
return self._number
number = property(fget=_get_number)
class class2(Acquisition.Explicit,Persistent):
''' a second simple class with some attributes and methods'''
__allow_access_to_unprotected_attributes__ = 1
_attribute1a = []
attribute2a = []
def __init__(self):
'''create a list of class1 objects in attribute1a'''
#i=1
#while i < 5:
# obj = class1(i)
# self._attribute1a.append(obj)
# i=i+1
self._attribute1a = class1(5)
def method1a(self):
'''instantiate class1 as object and return object usable by zope'''
obj = class1(5)
return obj.__of__(self)
def method2a(self):
'''returns class1.method1()'''
c1m1 = class1.method1()
return c1m1
def get_attribute1a(self):
#if self._attribute1a != []:
#i = len(self._attribute1a)
#j = 0
#while j != i-1:
# self._attribute1a[j] = self._attribute1a[j].__of__(self)
# j = j+1
#else:
obj = self._attribute1a
return obj.__of__(self)
attribute1a = property(fget=get_attribute1a)
attribute1b = property(fget=method1a)
attribute2b = property(fget=method2a)
Alexis Roda wrote:
> En/na kevin7kal ha escrit:
>> Ok, thank you for that.
>> I can create the list of objects from the __of__(self) attribute
>> without the wrapper error now,
>> but I still cannot access that attribute through zope.
>> Here is my code again, along with my zope content.
>
> Another thing I've missed, class1 isn't persistent, but you store
> instances in Zclass2.attribute1a. This can explain the "can't pickle"
> error.
>
>
>
> HTH
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
More information about the Zope
mailing list