parsing file

X

XspiriX

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top