Merging contents of two files

Ingo Blank spam at yourself.com
Wed May 15 14:55:07 EDT 2002


<Katharina.Pergens at dlr.de> schrieb im Newsbeitrag
news:3CE26265.54F83CAB at dlr.de...

I'm a beginner. What to do writing a Python script for searching the name of
the author of source files and generating an outputfile containing the
author name (containing in java source file), Explanation, File and Line
(containing in txt File; see below)

So, what I have is a text file (.txt) like the following:
            Abbreviation       Explanation.                 File
Line
                xyz                 comment for class
/home/de/abc.java            45
                ...
                        ...                               ..
This txt file contains of several lines and rows. The rows are sepearated by
tabs.
The source files (mentioned as File in txt file) are java files. I search in
the header for
    "* Created: dd/mm/yyy firstname.secondname"

How to write the script?

Thanks for your help!


Katharina,

look in the <string> module for functions "split","find" etc.
Files are read in with:

file = open("myFile.txt","r")
txt = file.read()
lines = string.split(txt,"\n"),

or line by line with fileinput.input() [See <fileinput> standard module].

It might also be worth looking into the module <re>, for splitting strings
via regular expressions.
Shouldn't you be familiar with regular expressions, consult some literature
because an explanation would go beyond the scope of this forum :-)

HTH

--ingo

voy NG arktb QBG qr [ rot13 ]





More information about the Python-list mailing list