[gt-users] python iterators
Sascha Steinbiss
steinbiss at zbh.uni-hamburg.de
Thu Oct 1 11:24:43 CEST 2009
Hi Brent,
thanks for your efforts!
> 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.
So do I. Is there any way to make both traversal strategies (DFS and
direct children only) possible? There are iterators for both of them,
and your patch only uses the DFS one. The __iter__() function can not
take kwargs parameters, or can it? I tried the following:
def __iter__(self, **kwargs):
if kwargs and kwargs["method"] == 'direct':
it = FeatureNodeIteratorDirect(self)
else:
it = FeatureNodeIteratorDepthFirst(self)
f = it.next()
while f is not None:
yield f
f = it.next()
but when trying this:
types = []
for f in fn(method="direct"):
types.append(f.type)
I got a "TypeError: 'FeatureNode' object is not callable". Any ideas?
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
More information about the gt-users
mailing list