Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-03 Thread Chris Withers
Raymond Hettinger wrote: In the first case, you would write: sets.extend(h.load(f)) yes, what I had was: for s in iter(h.load(f)): sets.append(s) ...which I mistakenly thought was working, but in in fact boils down to Raymond's code. The problem is that each item that h.load(f) returns

Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-02 Thread Boris Borcic
Sverker Nilsson wrote: Sverker Nilsson wrote: It reads one Stat object at a time and wants to report something when there is no more to be read from the file. Hmm, am I right in thinking the above can more nicely be written as: from guppy import hpy h = hpy() f = open(r'your.hpy')

Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-02 Thread Raymond Hettinger
I dont know guppy, but if h.load(f) raises StopIteration upon eof, as seems implied by your proposal, then something like the following would work. sets.extend(h.load(f) for _ in xrange(1e9)) Sounds like hpy has a weird API. Either it should be an iterator supporting __iter__() and next()