[gt-users] python iterators

Brent Pedersen bpederse at gmail.com
Wed Sep 30 17:51:45 CEST 2009


hi sascha, thanks for the feedback. i do like the iterator method, but
realize you have to think
about backward compatibility.
here's another option that just makes the feature itself
iterable--which actually is sorta nice:

for sub_feature in feature:
      print sub_feature

i've attached and even smaller patch to allow that. i think it's a
good way to keep the backwards compatiblity,
and i actually like it better.



On Wed, Sep 30, 2009 at 4:59 AM, Sascha Steinbiss
<steinbiss at zbh.uni-hamburg.de> wrote:
> Hi Brent,
>
>> hi, i've been looking at the python iterators and realized that the
>> iterating over featurenodes is not very idiomatic.
>
> This may be true, but we also wanted to preserve interface consistency
> across the supported programming languages, so at first we did not put
> much effort into fiting the interface to any specific language idioms.
> Of course, they are very nice to have anyway ;)
>
>> this is easily fixed by the patch below. it allows:
>>
>> for feat in FeatureNodeIteratorDepthFirst(node):
>>      print feat.type
>
> This is much more concise. However, in my opinion, it would be cleaner
> to have a traverse() iterator in the FeatureNodeIterator* classes:
>
> dfi = FeatureNodeIteratorDepthFirst(node)
> for feat in dfi.traverse():
>  print feat
>
> This allows the iterator class to be more backward compatible, with no
> iteration happening inside the constructor, while still having the
> iterator functionality if you want it:
>
> for feat in FeatureNodeIteratorDepthFirst(node).traverse():
>  print feat
>
> What do you think?
>
>> -brent
>
> Sascha
>
> --
> Sascha Steinbiss
> Center for Bioinformatics
> University of Hamburg
> Bundesstr. 43
> 20146 Hamburg
> Germany
>
> Email:  steinbiss at zbh.uni-hamburg.de
> URL:    http://www.zbh.uni-hamburg.de/steinbiss
> Phone:  +49 (40) 42838 7322
> FAX:    +49 (40) 42838 7312
>
> _______________________________________________
> gt-users mailing list
> gt-users at genometools.org
> http://genometools.org/mailman/listinfo/gt-users
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterators.2..diff
Type: text/x-diff
Size: 1665 bytes
Desc: not available
Url : http://genometools.org/pipermail/gt-users/attachments/20090930/966beb03/attachment.bin 


More information about the gt-users mailing list