Re: [Numpy-discussion] loadtxt stop

2010-09-19 Thread Zachary Pincus
>> Though, really, it's annoying that numpy.loadtxt needs both the >> readline function *and* the iterator protocol. If it just used >> iterators, you could do: >> >> def truncator(fh, delimiter='END'): >> for line in fh: >>if line.strip() == delimiter: >> break >>yield line >> >> num

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Benjamin Root
On Fri, Sep 17, 2010 at 3:04 PM, Zachary Pincus wrote: > On Sep 17, 2010, at 3:59 PM, Benjamin Root wrote: > > > So, this code will still raise an error for an empty file. > > Personally, I consider that a bug because I would expect to receive > > an empty array. I could understand raising an err

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Zachary Pincus
On Sep 17, 2010, at 3:59 PM, Benjamin Root wrote: > So, this code will still raise an error for an empty file. > Personally, I consider that a bug because I would expect to receive > an empty array. I could understand raising an error for a non-empty > file that does not contain anything u

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Benjamin Root
On Fri, Sep 17, 2010 at 2:50 PM, Zachary Pincus wrote: > > Though, really, it's annoying that numpy.loadtxt needs both the > > readline function *and* the iterator protocol. If it just used > > iterators, you could do: > > > > def truncator(fh, delimiter='END'): > > for line in fh: > > if li

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Zachary Pincus
> Though, really, it's annoying that numpy.loadtxt needs both the > readline function *and* the iterator protocol. If it just used > iterators, you could do: > > def truncator(fh, delimiter='END'): > for line in fh: > if line.strip() == delimiter: > break > yield line > > numpy.load

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Zachary Pincus
>> In the end, the question was; is worth adding start= and stop= >> markers >> into loadtxt to allow grabbing sections of a file between two known >> headers? I imagine it's something that people come up against >> regularly. Simple enough to wrap your file in a new file-like object that st

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Christopher Barker
Neil Hodgson wrote: > In the end, the question was; is worth adding start= and stop= markers > into loadtxt to allow grabbing sections of a file between two known > headers? I imagine it's something that people come up against regularly. maybe not so regular. However, a common use would be to b

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Pierre GM
On Sep 17, 2010, at 2:40 PM, Neil Hodgson wrote: > oops, I meant to save my post but I sent it instead - doh! > > In the end, the question was; is worth adding start= and stop= markers into > loadtxt to allow grabbing sections of a file between two known headers? I > imagine it's something t

Re: [Numpy-discussion] loadtxt stop

2010-09-17 Thread Neil Hodgson
oops, I meant to save my post but I sent it instead - doh! In the end, the question was; is worth adding start= and stop= markers into loadtxt to allow grabbing sections of a file between two known headers? I imagine it's something that people come up against regularly. Thanks, Neil ___

[Numpy-discussion] loadtxt stop

2010-09-17 Thread Neil Hodgson
Hi, I been looking around and could spot anything on this. Quite often I want to read a homogeneous block of data from within a file. The skiprows option is great for missing out the section before the data starts, but if there is anything below then loadtxt will choke. I wondered if there w