Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > parsing file

Reply
Thread Tools

parsing file

 
 
XspiriX
Guest
Posts: n/a
 
      07-16-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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
In file parsing, taking the first few characters of a text file after a readfile or streamreader file read... .Net Sports ASP .Net 11 01-17-2006 12:44 AM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments