Re: Parsing of a file

2008-08-07 Thread Tommy Grav
On Aug 7, 2008, at 12:52 PM, Mike Driscoll wrote: I'm well aware of the split() method and built-ins, however since this appeared to be a homework-type question and I was at work, I didn't spend any time on the issue. The only reason I mentioned McGuire's PyParsing module was because I had just

Re: Parsing of a file

2008-08-07 Thread Mike Driscoll
On Aug 6, 4:06 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 7, 6:02 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > > > > > On Aug 6, 1:55 pm, Tommy Grav <[EMAIL PROTECTED]> wrote: > > > > I have a file with the format > > > > Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Fr

Re: Parsing of a file

2008-08-07 Thread Bruno Desthuilliers
Tommy Grav a écrit : I have a file with the format Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames 5 Set 1 Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames 5 Set 2 Field f31226: Ra=20:24:45.50 Dec=+78:26:45.2 MJD=53370.06823860 Frames 5 Set 3 Field

Re: Parsing of a file

2008-08-06 Thread bearophileHUGS
Paul McGuire: > This code creates a single dict for the input lines, keyed by id. > Each value contains elements labeled 'id', 'ra', and 'mjd'. ... > d = dict( > (rec.split()[1][:-1], > dict([('id',rec.split()[1][:-1])] + > [map(str.lower,f.split('=')) >

Re: Parsing of a file

2008-08-06 Thread Paul McGuire
On Aug 6, 3:14 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > Regular expressions will do the trick nicely. > Or just use str.split, and create dicts using dict(list_of_tuples) constructor. This code creates a single dict for the input lines, keyed by id. Each value contains elements labeled '

Re: Parsing of a file

2008-08-06 Thread Henrique Dante de Almeida
On Aug 6, 3:55 pm, Tommy Grav <[EMAIL PROTECTED]> wrote: > I have a file with the format > > Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames   > 5 Set 1 > Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames   > 5 Set 2 > Field f31226: Ra=20:24:45.50 Dec=+78

Re: Parsing of a file

2008-08-06 Thread John Machin
On Aug 7, 7:06 am, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 7, 6:02 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > > > > > On Aug 6, 1:55 pm, Tommy Grav <[EMAIL PROTECTED]> wrote: > > > > I have a file with the format > > > > Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Fr

Re: Parsing of a file

2008-08-06 Thread bearophileHUGS
Using something like PyParsing is probably better, but if you don't want to use it you may use something like this: raw_data = """ Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames 5 Set 1 Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames 5 Set 2 Field f31

Re: Parsing of a file

2008-08-06 Thread John Machin
On Aug 7, 6:02 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On Aug 6, 1:55 pm, Tommy Grav <[EMAIL PROTECTED]> wrote: > > > > > I have a file with the format > > > Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames > > 5 Set 1 > > Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJ

Re: Parsing of a file

2008-08-06 Thread Stefan Behnel
Shawn Milochik wrote: >> I would like to parse this file by extracting the field id, ra, dec and mjd >> for each line. It is >> not, however, certain that the width of each value of the field id, ra, dec >> or mjd is the same >> in each line. Is there a way to do this such that even if there was a

Re: Parsing of a file

2008-08-06 Thread Shawn Milochik
> > I would like to parse this file by extracting the field id, ra, dec and mjd > for each line. It is > not, however, certain that the width of each value of the field id, ra, dec > or mjd is the same > in each line. Is there a way to do this such that even if there was a line Regular expressions

Re: Parsing of a file

2008-08-06 Thread Mike Driscoll
On Aug 6, 1:55 pm, Tommy Grav <[EMAIL PROTECTED]> wrote: > I have a file with the format > > Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames   > 5 Set 1 > Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames   > 5 Set 2 > Field f31226: Ra=20:24:45.50 Dec=+78

Parsing of a file

2008-08-06 Thread Tommy Grav
I have a file with the format Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames 5 Set 1 Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames 5 Set 2 Field f31226: Ra=20:24:45.50 Dec=+78:26:45.2 MJD=53370.06823860 Frames 5 Set 3 Field f31004: Ra=20:25:0