parsing file

Discussion in 'Python' started by XspiriX, Jul 16, 2003.

  1. XspiriX

    XspiriX Guest

    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.
    XspiriX, Jul 16, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    873
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    579
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    610
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    435
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    729
    John Levine
    Feb 2, 2012
Loading...

Share This Page