> > 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:
> >
> > ###
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.
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.
> 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]
>
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]]