parsing file

XspiriX chp01as at shef.ac.uk
Wed Jul 16 11:31:35 CEST 2003


Hi
I am new here and so in python :-)
I am trying to make a script for extracting (parsing?) some values from 
a file and write them into an output
i thought to follow this example (cookbook):

#!/usr/bin/env python
import os, sys

nargs = len(sys.argv)

if not 3 <= nargs <= 5:
    print "usage: %s search_text replace_text [infile [outfile]]" % \
        os.path.basename(sys.argv[0])
else:
    stext = sys.argv[1]
    rtext = sys.argv[2]
    input = sys.stdin
    output = sys.stdout
    if nargs > 3:
        input = open(sys.argv[3])
    if nargs > 4:
        output = open(sys.argv[4], 'w')
    for s in input.xreadlines():
        output.write(s.replace(stext, rtext))
    output.close()
    input.close()
indeed this search and replace the text, so I am thinking to take off 
the code part about the replacement and to add something else. may you 
give me some suggestion? sorry if it looks like a newbie question....if 
it so just ignore it ;-)

cheers

-- 
enjoy
XspiriX
Mathematics is the language of nature.
Everything around us can be represented and understood
through numbers.





More information about the Python-list mailing list