gawain_ 0 Newbie Poster

Hi everybody.
Maybe I was able to write a script which takes an input file, strips off part of the anchor tag(<a ....>) and returns a new file.
I'd like to know your opinion about the script; it works, but I have the feeling that there is something that can be writen better. The script goes like this
From shell: python python_file.py inputfile.txt

import re
import sys

nargs = len(sys.argv)

#newefile.txt is the output file
w=open('newfile.txt', 'w')
if nargs > 1:
    myfile = sys.argv[1]
    output = open( myfile )
    regex = re.compile( r'(ADD_DATE=[^>]*)>' )
    lines = output.readlines()
   
    for line in lines:
        formatted = regex.sub('>', line )
        w.write(formatted)
     
    output.close()
w.close()

PS: what the regex is meant ot be is to clean the tags saved in the bookmar of the browser.
Thanks for any correction and improvment

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.