RE: [Zope] Access to Python arrays
From: Edward Muller >I am working on a product in which one of the objects keeps an array. I've >already overcome the problems with making the array persistent (i.e. by not >using .append, but intead re-assigning the array each time). Anyway...I >digress.. It is probably easier to write: self._p_changed = 1 # Trigger persistence at the end of a method where you use mutable properties. the: tempList = self.contentList tempList.append(newContent) self.contentList = tempList gets tired real fast especially if you have more than one list you need to update. self.contentList.append(newContent) self._p_changed = 1 Is so much simpler, and makes the code much easier to read. A way you might cheat persistence could be to (untested): self.id = self.id But then again, why do that when you only need to set _p_change to true. The persistence doesn't get triggered for every parameter. Either an object has changed or it hasn't. So you don't have to trigger it individually for every list or whatever you use in your object. regards Max M Max M. W. Rasmussen,Denmark. New Media Director private: [EMAIL PROTECTED] work: [EMAIL PROTECTED] - Specialization is for insects. - Robert A. Heinlein ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Access to Python arrays
> I am working on a product in which one of the objects keeps an array. I've > already overcome the problems with making the array persistent (i.e. by not > using .append, but intead re-assigning the array each time). Anyway...I > digress.. This sounds a bit awkward, if you could post some of the code (or release an alpha version of your product, that'd give us a context..). > This prints out the id of each of my objects. But I ALSO want to print out the > contents of the array, indented after each instances id. What is the best way > to >do this in DTML? Is there as way? Lets say for arguments sake that each > array element is a string, how do I iterate through the array and print the > strings. If your class is defined somewhere along these lines: class myclass(Persistent, Yadayada, yada): def __init__(self, id, body): self.idself.body you could easiliy display the body of the object within the dtml-in loop using the same approach as with with id, . If you're wondering how to display _the entire object_, then defining a __call__ would probably be the right thing, and you could do the loop like this: > Lets say each element in the array is anothe array (of 5 elements), How do > I loop over the array and pull out the sub arrays and print those five > elements? Easy enough: This is the contents of one of the array elements contained within an object with meta type : > Any help/direction would be appreciated, I've checked the docs and refered to > some sample products but I either missed something obvious (probable) or It's > hard..or something :-) Well, hope this helps then. I'd also recommend reading the Python tutorial, and other introductory Python material, if you're not familiar with it. -Morten ___ Zope maillist - [EMAIL PROTECTED] 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] Access to Python arrays
I am working on a product in which one of the objects keeps an array. I've already overcome the problems with making the array persistent (i.e. by not using .append, but intead re-assigning the array each time). Anyway...I digress.. So I have this object that has an array..A folder may contain several of these items, so I loop over them in DTML like this: This prints out the id of each of my objects. But I ALSO want to print out the contents of the array, indented after each instances id. What is the best way to do this in DTML? Is there as way? Lets say for arguments sake that each array element is a string, how do I iterate through the array and print the strings. Lets say each element in the array is anothe array (of 5 elements), How do I loop over the array and pull out the sub arrays and print those five elements? Any help/direction would be appreciated, I've checked the docs and refered to some sample products but I either missed something obvious (probable) or It's hard..or something :-) -- ...EAM... [EMAIL PROTECTED] [EMAIL PROTECTED] --- 'It's because crappy programs offend me.' --Eric Raymond Grow a ponytail -- view it as your telepathic antenna to other Linux Kernel Developers. -- Jeff V. Merkey ___ Zope maillist - [EMAIL PROTECTED] 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 )