title: In Python how to remove a range of lines from a file without using fileinput module
body: <p>I am trying to remove a range of lines passed from the command line to a Python script. That means, I will pass the input file name, starting line number(from where to start removing)  and number of lines to be removed from the input file. I have tried that using fileinput module and that is working.
  Command to run from my unix prompt is :</p>
  
  <p>python script.py inputfile 2 6 </p>
  
  <p>Below is the code for that :</p>
  
  <pre><code>#!/usr/bin/python
  import fileinput
  import sys
  
  filename, start, upto = sys.argv[1:4]
  start, upto = int(start), int(upto)
  
  for line in fileinput.input(filename, inplace=1, backup='.orig'):
  
      if start &lt;= fileinput.lineno() &lt; start + upto:
          pass
      else:
          print line[:-1]
  
  fileinput.close()
  </code></pre>
  
  <p>However, my requirement is to do the same without using fileinput. I have been able to try upto some extent and below is my tried code. The output should exactly be as same as the previous code. Keeping a back up file can be ignored though. If anybody can  help me to achieve the requirement, would be of great help. Thanks.</p>
  
  <pre><code>#!/usr/bin/python
  #import fileinput
  import sys
  
  filename, start, upto = sys.argv[1:4]
  start, upto = int(start), int(upto)
  
  f =  open(filename, "r+")
  for lineno, line in enumerate(f):
  
      if start &lt;= lineno &lt; start + upto:
          length = len(line)
          f.seek(-length, 1)
          f.write("")
  
  f.close()
  </code></pre>