[Tutor] using python for parsing

Makarand Datar datar at wisc.edu
Sat Jun 29 20:00:20 CEST 2013


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 <datar at wisc.edu> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130629/b3cd6551/attachment.html>


More information about the Tutor mailing list