[Tutor] using python for parsing

2013-06-26 Thread Makarand Datar
Hi,

I know practically nothing about python. I know how to install it and all
that kind of stuff. I want to use python for parsing a text file. The task
is to read in a text file, and write out another text file that is written
in some particular way using the data from the file that was read in. The
question is how do I go about this? What part of python documentation, or a
book I should read etc. I dont want to start reading a python book from the
first page. I just want to do this parsing task and I will learn about
whatever I need to as I encounter it.

Thank you for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using python for parsing

2013-07-10 Thread Makarand Datar
Hi,

So I am able to read in a file, and write out a file from python. I have
some question about the text manipulation that I need to do between reading
in a file and spitting out another. Couple of things I would like to do,
are: if the first character of a line is a comma, I would like to delete
the newline character at the end of the previous line and make a longer
line (one line followed by another without a newline in between); if the
first character of the line is an exclamation mark, I would like to delete
that line altogether. So for instance, if the input file text looks like
the following,

one, two, three
, four, five, six
! This is a comment
seven, eight, nine

I would like to output a file the text in which looks like

one, two, three, four, five, six
seven, eight, nine

This is to get me going on this and I will have to do a LOT of text
manipulation beyond this. So any tips in general are highly appreciated.
Thank you

On Wed, Jun 26, 2013 at 12:05 PM, Makarand Datar  wrote:

> Hi,
>
> I know practically nothing about python. I know how to install it and all
> that kind of stuff. I want to use python for parsing a text file. The task
> is to read in a text file, and write out another text file that is written
> in some particular way using the data from the file that was read in. The
> question is how do I go about this? What part of python documentation, or a
> book I should read etc. I dont want to start reading a python book from the
> first page. I just want to do this parsing task and I will learn about
> whatever I need to as I encounter it.
>
> Thank you for the help.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Interpret the contents of a line

2013-07-18 Thread Makarand Datar
Hi,

I am working on a parser and my input file is a description about bunch of
things written line by line. So for instance, consider the following two
lines and what the corresponding variables in python should look like.

example Line1: position = 1, 1, rotation = 90, 0, 0, mass = 120; Here I
want the variables to be position = [1,1,0], rotation = [90,0,0], mass =
[120]
example Line2: position = 1, 1, 2, mass = 120, rotation = 90, 0; Here I
want the variables to be position = [1,1,2], rotation = [90,0,0], mass =
[120]
example Line3: mass = 120, rotation = 90, 0; Here I want the variables to
be position = [0,0,0], rotation = [90,0,0], mass = [120]

I know the maximum number of arguments possible for each variable. For
example, in the first line above, only two numbers for position ares
specified; that means that the third entry in position list is zero. So I
need to handle these cases while reading in the file as well. Additionally,
the text might not always be in the same order; like shown in the second
line above. And finally, sometimes numbers for one variable might not exist
at all; like shown in line 3. Here, the position is then read as position =
[0,0,0].
How do I implement such stuff? Is there some smart way of doing this? All I
have in mind is this: read a line as comma or a space delimited list of
words variable and then some how use if else + len(list) to figure out
whats going on. But that seems way too tedious and I feel that there might
be an easier way to read such things.

Any help is highly appreciated.
Thank you
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor