By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

simple deleting problem

P: 5
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.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/python
  2. input = open('/boot/config', 'r')
  3. output = open('/tmp/config', 'w')
  4. lines = input.readlines()
  5. number = 0
  6. for line in lines:
  7.     if line[0] == "#":
  8.         del lines[number]
  9.     else: number += 1
  10. for y in range(len(lines)):
  11.     output.writelines('%s' % lines[y])
  12. output.close()
  13.  
Thanks.
Apr 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: 43
Expand|Select|Wrap|Line Numbers
  1. input.close()
  2. for line in lines:
  3.    line=line.strip()
  4.    if not line.startswith( "#" ):
  5.       output.write('%s\n' % (line))
  6. output.close()
Apr 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.