Re: On text processing

2007-03-23 Thread Daniel Nogradi
> > I'm in a process of rewriting a bash/awk/sed script -- that grew to > > big -- in python. I can rewrite it in a simple line-by-line way but > > that results in ugly python code and I'm sure there is a simple > > pythonic way. > > > > The bash script processed text files of the form: > > > > ###

Re: On text processing

2007-03-23 Thread Paul McGuire
On Mar 23, 5:30 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote: > Hi list, > > I'm in a process of rewriting a bash/awk/sed script -- that grew to > big -- in python. I can rewrite it in a simple line-by-line way but > that results in ugly python code and I'm sure there is a simple > pythonic way.

Re: On text processing

2007-03-23 Thread Paddy
On Mar 23, 10:30 pm, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote: > Hi list, > > I'm in a process of rewriting a bash/awk/sed script -- that grew to > big -- in python. I can rewrite it in a simple line-by-line way but > that results in ugly python code and I'm sure there is a simple > pythonic way.

Re: On text processing

2007-03-23 Thread Daniel Nogradi
> This is my first try: > > ddata = {} > > inside_matrix = False > for row in file("data.txt"): > if row.strip(): > fields = row.split() > if len(fields) == 2: > inside_matrix = False > ddata[fields[0]] = [fields[1]] > lastkey = fields[0] >

Re: On text processing

2007-03-23 Thread bearophileHUGS
Daniel Nogradi: > Any elegant solution for this? This is my first try: ddata = {} inside_matrix = False for row in file("data.txt"): if row.strip(): fields = row.split() if len(fields) == 2: inside_matrix = False ddata[fields[0]] = [fields[1]]

On text processing

2007-03-23 Thread Daniel Nogradi
Hi list, I'm in a process of rewriting a bash/awk/sed script -- that grew to big -- in python. I can rewrite it in a simple line-by-line way but that results in ugly python code and I'm sure there is a simple pythonic way. The bash script processed text files of the form: ###

Re: Beginner question on text processing

2006-12-29 Thread skip
Harold> To illustrate, assume I have a text file, call it test.txt, with Harold> the following information: Harold> X11 .32 Harold> X22 .45 Harold> My goal in the python program is to manipulate this file such Harold> that a new file would be created that looks like:

Beginner question on text processing

2006-12-29 Thread Doran, Harold
I am beginning to use python primarily to organize data into formats needed for input into some statistical packages. I do not have much programming experience outside of LaTeX and R, so some of this is a bit new. I am attempting to write a program that reads in a text file that contains some value