Re: file reading by record separator (not line by line)

2007-06-02 Thread Steve Howell
--- Steve Howell <[EMAIL PROTECTED]> wrote: > > Can I suggest a minor optimization? > > Instead of this... > > def get_predicate(arg): > return arg if callable(arg) else ( >arg.__eq__ if hasattr(arg,'__eq__') > else >lambda item: item == arg) > Neve

Re: file reading by record separator (not line by line)

2007-06-02 Thread Steve Howell
--- George Sakkis <[EMAIL PROTECTED]> wrote: > > It seems > > like it would be fairly straightforward to do a > quick > > prototype implementation of this. I'm off to work > > soon, so I can't do it today, but maybe Sunday. > > I'm afraid I beat you to it :) > http://aspn.activestate.com/ASPN/

Re: file reading by record separator (not line by line)

2007-06-02 Thread George Sakkis
On Jun 1, 7:00 am, Steve Howell <[EMAIL PROTECTED]> wrote: > --- Tijs <[EMAIL PROTECTED]> wrote: > > > Yes, or a single one that takes a wide range of > > construction possibilities, > > like strings, lambdas or regexes in various keyword > > parameters. > > > BlockReader(f, start='>') > > BlockRea

Re: file reading by record separator (not line by line)

2007-06-01 Thread Neil Cerutti
On 2007-06-01, Tijs <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: >>> >>> from blockread import BlockReader >>> >>> b = BlockReader(f, boundary='>') >>> for block in b: >>> # whatever >> >> Yep, I like this idea. You might have a few >> variations: > > Yes, or a single one that takes

Re: file reading by record separator (not line by line)

2007-06-01 Thread Tijs
Steve Howell wrote: > Do you have any free time on your hands? Nope. I think Python is a programmer's language, not a whack-something-together script language for text processing (although it is used that way). Any decent programmer has no need of this construct, since the time to lookup how

Re: file reading by record separator (not line by line)

2007-06-01 Thread Steve Howell
--- Tijs <[EMAIL PROTECTED]> wrote: > > Yes, or a single one that takes a wide range of > construction possibilities, > like strings, lambdas or regexes in various keyword > parameters. > > BlockReader(f, start='>') > BlockReader(f, start=re.compile('>|<'), end='---') > BlockReader(f, start=lambd

Re: file reading by record separator (not line by line)

2007-06-01 Thread Tijs
Steve Howell wrote: >> >> from blockread import BlockReader >> >> b = BlockReader(f, boundary='>') >> for block in b: >> # whatever >> > > Yep, I like this idea. You might have a few > variations: > Yes, or a single one that takes a wide range of construction possibilities, like str

Re: file reading by record separator (not line by line)

2007-06-01 Thread Steve Howell
--- Tijs <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > [...] but I wonder if the Python community > > couldn't help a lot of newbies (or insufficiently > > caffeinated non-newbies) by any of the following: > > > Well, I'm not a newbie, and I always make sure to be > thoroughly caffeinated

Re: file reading by record separator (not line by line)

2007-06-01 Thread Tijs
Steve Howell wrote: > > > I think itertools.groupby() is usually the key > batteries-included component in elegant solutions to > this problem, but I wonder if the Python community > couldn't help a lot of newbies (or insufficiently > caffeinated non-newbies) by any of the following: > Well, I

Re: file reading by record separator (not line by line)

2007-05-31 Thread Hendrik van Rooyen
"Lee Sander" <[EMAIL PROTECTED]>wrote: > I wanted to also say that this file is really huge, so I cannot > just do a read() and then split on ">" to get a record > thanks > lee > > On May 31, 1:26 pm, Lee Sander <[EMAIL PROTECTED]> wrote: > > Dear all, > > I would like toreada really hugefileth

Re: file reading by record separator (not line by line)

2007-05-31 Thread Steve Howell
--- Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > There was just recently a thread with a > `itertools.groupby()` solution. Yes, indeed. I think it's a very common coding problem (with plenty of mostly analogous variations) that has these very common pitfalls: 1) People often forget t

Re: file reading by record separator (not line by line)

2007-05-31 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Lee Sander wrote: > Dear all, > I would like to read a really huge file that looks like this: > >> name1 > line_11 > line_12 > line_13 > ... >>name2 ... > line_21 > line_22 > ... > etc > > where line_ij is just a free form text on that line. > > how can i read file s

Re: file reading by record separator (not line by line)

2007-05-31 Thread Tijs
aspineux wrote: > > something like > > name=None > lines=[] > for line in open('yourfilename.txt'): > if line.startwith('>'): > if name!=None: > print 'Here is the record', name > print lines > print > name=line.stripr('\r') > lines

Re: file reading by record separator (not line by line)

2007-05-31 Thread Tijs
Lee Sander wrote: > I wanted to also say that this file is really huge, so I cannot > just do a read() and then split on ">" to get a record > thanks > lee Below is the easy solution. To get even better performance, or if '<' is not always at the start of the line, you would have to implement the

Re: file reading by record separator (not line by line)

2007-05-31 Thread aspineux
something like name=None lines=[] for line in open('yourfilename.txt'): if line.startwith('>'): if name!=None: print 'Here is the record', name print lines print name=line.stripr('\r') lines=[] else: lines.append(line.str

Re: file reading by record separator (not line by line)

2007-05-31 Thread Lee Sander
I wanted to also say that this file is really huge, so I cannot just do a read() and then split on ">" to get a record thanks lee On May 31, 1:26 pm, Lee Sander <[EMAIL PROTECTED]> wrote: > Dear all, > I would like toreada really hugefilethat looks like this: > > > name1 > > line_11 > line_12