[PEAK] How do I extract a subset?

Peter Damoc pdamoc at gmail.com
Wed Apr 16 13:06:39 EDT 2008


Hi Phillip,

I tried a naive

fitered_records = [r for r in records if "some segment" in r.name]

It didn't work :)
I get:
peak.events.trellis.InputConflict: (Set([]), [])

as for changes, here is the code:

    @trellis.observer
    def updateView(self):
        x = len(self.records) # needed to monitor changes
        if self.sorted_records:
            self.txt.Clear()
            for r in self.sorted_records:
                self.txt.AppendText(self.fmt.format(r)+"\n")

if I remove the first line in the method the observer no longer gets
triggered.
In all cases the only thing that changes are new record being added to the
records set.

Peter

On Wed, Apr 16, 2008 at 6:19 PM, Phillip J. Eby <pje at telecommunity.com>
wrote:

> At 11:32 AM 4/16/2008 +0300, Peter Damoc wrote:
>
> > Hello,
> >
> > I have an app where I use a trellis.Set to hold some records, a
> > trellis.SortedSet to keep them in order but now I need to filter the records
> > based on some criteria.
> >
> > records = trellis.Set()
> > filtered_records = trellis.???
> > sorted_records = trellis.SortedSet(data=filtered_records)
> >
> > How can I do this?
> >
>
> In the simple case, you could just write a rule that returns a new set.
>  If you want to be more sophisticated, you can write a rule that adds or
> deletes records in filtered_records using records.added and records.deleted.
>
>
>  Also, if I have an observer that watches over sorted_records, shouldn't
> > it be triggered if a change in the  underlying set is made?
> >
>
> Yes.  Of course, by "change" here, it would mean additions or removals
> from the set, not changes to mutable values associated with those objects.
>  SortedSet is intended for sets of immutable objects at the present time.
>
>


-- 
There is NO FATE, we are the creators.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20080416/988768fd/attachment.html


More information about the PEAK mailing list