Re: Record seperator

2011-08-28 Thread greymaus
On 2011-08-27, Steven D'Aprano wrote: > greymaus wrote: > >> On 2011-08-26, D'Arcy J.M. Cain wrote: >>> On 26 Aug 2011 18:39:07 GMT >>> greymaus wrote: Is there an equivelent for the AWK RS in Python? as in RS='\n\n' will seperate a file at two blank line interva

Re: Record seperator

2011-08-27 Thread Dan Stromberg
http://stromberg.dnsalias.org/svn/bufsock/trunk does it. $ cat double-file daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh root:x:0:0:root:/roo

Re: Record seperator

2011-08-27 Thread Terry Reedy
On 8/27/2011 5:07 PM, Roy Smith wrote: In article, Terry Reedy wrote: On 8/27/2011 1:45 PM, Roy Smith wrote: In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: open("file.txt") # opens the file .read() # reads the contents of the fi

Re: Record seperator

2011-08-27 Thread Roy Smith
In article , Terry Reedy wrote: > On 8/27/2011 1:45 PM, Roy Smith wrote: > > In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> open("file.txt") # opens the file > >> .read() # reads the contents of the file > >> .split("\n\n")

Re: Record seperator

2011-08-27 Thread Chris Angelico
On Sun, Aug 28, 2011 at 6:03 AM, Terry Reedy wrote: >      yield para # or ''.join(para), as desired > Or possibly '\n'.join(para) if you want to keep the line breaks inside paragraphs. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Record seperator

2011-08-27 Thread Terry Reedy
On 8/27/2011 1:45 PM, Roy Smith wrote: In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: open("file.txt") # opens the file .read() # reads the contents of the file .split("\n\n")# splits the text on double-newlines. The biggest prob

Re: Record seperator

2011-08-27 Thread ChasBrown
On Aug 27, 10:45 am, Roy Smith wrote: > In article <4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, >  Steven D'Aprano wrote: > > > open("file.txt")   # opens the file > >  .read()           # reads the contents of the file > >  .split("\n\n")    # splits the text on double-newlines. > > Th

Re: Record seperator

2011-08-27 Thread Roy Smith
In article <4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n")# splits the text on double-newlines. The biggest problem with this code is that read() slurp

Re: Record seperator

2011-08-27 Thread Steven D'Aprano
greymaus wrote: > On 2011-08-26, D'Arcy J.M. Cain wrote: >> On 26 Aug 2011 18:39:07 GMT >> greymaus wrote: >>> >>> Is there an equivelent for the AWK RS in Python? >>> >>> >>> as in RS='\n\n' >>> will seperate a file at two blank line intervals >> >> open("file.txt").read().split("\n\n") >> >

Re: Record seperator

2011-08-27 Thread greymaus
On 2011-08-26, D'Arcy J.M. Cain wrote: > On 26 Aug 2011 18:39:07 GMT > greymaus wrote: >> >> Is there an equivelent for the AWK RS in Python? >> >> >> as in RS='\n\n' >> will seperate a file at two blank line intervals > > open("file.txt").read().split("\n\n") > Ta!.. bit awkard. :)) -

Re: Record seperator

2011-08-26 Thread D'Arcy J.M. Cain
On 26 Aug 2011 18:39:07 GMT greymaus wrote: > > Is there an equivelent for the AWK RS in Python? > > > as in RS='\n\n' > will seperate a file at two blank line intervals open("file.txt").read().split("\n\n") -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy

Record seperator

2011-08-26 Thread greymaus
Is there an equivelent for the AWK RS in Python? as in RS='\n\n' will seperate a file at two blank line intervals -- maus . . ... NO CARRIER -- http://mail.python.org/mailman/listinfo/python-list

Re: input record seperator (equivalent of "$|" of perl)

2004-12-20 Thread Fredrik Lundh
Scott David Daniels wrote: > True. The 2.4 document says that itertools.groupby() is equivalent to: > > class groupby(object): > So you could always just use that code. the right way to do that is to use the Python version as a fallback: try: from itertools import groupby ex

Re: input record seperator (equivalent of "$|" of perl)

2004-12-20 Thread Scott David Daniels
Gábor Farkas wrote: Scott David Daniels wrote: If you have python 2.3 or 2.4, you have itertools. for me it seems that 2.3 does not have itertools.groupby. it has itertools, but not itertools.groupby. True. The 2.4 document says that itertools.groupby() is equivalent to: class groupby(object):

Re: input record seperator (equivalent of "$|" of perl)

2004-12-20 Thread Nick Coghlan
[EMAIL PROTECTED] wrote: I would like to read this file as a record. I can do this in perl by defining a record seperator; is there an equivalent in python? Depending on your exact use case, you may also get some mileage out of using the csv module with a custom delimeter. Py> from csv imp

Re: input record seperator (equivalent of "$|" of perl)

2004-12-20 Thread Gábor Farkas
Scott David Daniels wrote: M.E.Farmer wrote: I dont have itertools yet. That module looks like it rocks. thanks for the pointers, M.E.Farmer If you have python 2.3 or 2.4, you have itertools. for me it seems that 2.3 does not have itertools.groupby. it has itertools, but not itertools.groupby. act

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread M.E.Farmer
Yea I should have mentioned I am running python 2.2.2. Can it be ported to python 2.2.2? Till they get python 2.4 all up and runningI'll wait a bit. Thanks for the info, M.E.Farmer Scott David Daniels wrote: > M.E.Farmer wrote: > > I dont have itertools yet. That module looks like it rocks. >

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread Scott David Daniels
M.E.Farmer wrote: I dont have itertools yet. That module looks like it rocks. thanks for the pointers, M.E.Farmer If you have python 2.3 or 2.4, you have itertools. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread M.E.Farmer
Fredrik, Thanks didn't realize that about reading a file on a for loop. Slick! By the way the code I posted was an attempt at not building a monolithic memory eating list like you did to return the values in your second example. Kinda thought it would be nice to read them as needed instead of all a

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread Fredrik Lundh
"M.E.Farmer" wrote: > What about a generator and xreadlines for those really large files: when you loop over a file object, Python uses a generator and a xreadlines- style buffering system to read data as you go. (if you check the on-line help, you'll notice that xreadlines itself is only provid

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread M.E.Farmer
name > profession > id > # > name2 > profession3 > id2 > > I would like to read this file as a record. > I can do this in perl by defining a record seperator; > is there an equivalent in python? > thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread Doug Holton
[EMAIL PROTECTED] wrote: Hi, I know that i can do readline() from a file object. However, how can I read till a specific seperator? for exmple, if my files are name profession id # name2 profession3 id2 I would like to read this file as a record. I can do this in perl by defining a record

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread Keith Dart
[EMAIL PROTECTED] wrote: Hi, I know that i can do readline() from a file object. However, how can I read till a specific seperator? for exmple, if my files are name profession id # name2 profession3 id2 I would like to read this file as a record. I can do this in perl by defining a record

Re: input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread Fredrik Lundh
his file as a record. > I can do this in perl by defining a record seperator; > is there an equivalent in python? not really; you have to do it manually. if the file isn't too large, consider reading all of it, and splitting on the separator: for record in file.read().split(sepa

input record seperator (equivalent of "$|" of perl)

2004-12-19 Thread les_ander
Hi, I know that i can do readline() from a file object. However, how can I read till a specific seperator? for exmple, if my files are name profession id # name2 profession3 id2 I would like to read this file as a record. I can do this in perl by defining a record seperator; is there an