simple deleting problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aLiase
    New Member
    • Nov 2007
    • 5

    simple deleting problem

    I need some help figuring out what the problem on this. It actually a simple program that just read lines that has comment of #, if it does it delete that line and moves on. But for some reason it not working very well.

    Code:
    #!/bin/python
    input = open('/boot/config', 'r')
    output = open('/tmp/config', 'w')
    lines = input.readlines()
    number = 0
    for line in lines:
    	if line[0] == "#":
    		del lines[number]
    	else: number += 1
    for y in range(len(lines)):
    	output.writelines('%s' % lines[y])
    output.close()
    Thanks.
  • woooee
    New Member
    • Mar 2008
    • 43

    #2
    Code:
    input.close()
    for line in lines:
       line=line.strip()
       if not line.startswith( "#" ):
          output.write('%s\n' % (line))
    output.close()

    Comment

    Working...