title: os.remove() in windows gives "[Error 32] being used by another process"
body: <p>I know this question has been asked before quiet a lot on SO and elsewhere too. I still couldn't get it done. And im sorry if my English is bad</p>
  
  <p>Removing file in linux was much more simpler. Just <code>os.remove(my_file)</code> did the job, But in windows it gives </p>
  
  <pre><code>    os.remove(my_file)
  WindowsError: [Error 32] The process cannot access the file because it is being used by another process: (file-name)
  </code></pre>
  
  <p><strong><em>my code :</em></strong></p>
  
  <pre><code>line_count = open(my_file, mode='r')        #
  t_lines = len(line_count.readlines())       # For total no of lines
  outfile = open(dec_file, mode='w')
  with open(my_file, mode='r') as contents:
      p_line = 1
      line_infile = contents.readline()[4:]
      while line_infile:
          dec_of_line = baseconvert(line_infile.rstrip(),base16,base10)
          if p_line == t_lines:
              dec_of_line += str(len(line_infile)).zfill(2)
              outfile.write(dec_of_line + "\r\n")
          else:
              outfile.write(dec_of_line + "\r\n")
          p_line += 1
          line_infile = contents.readline()[4:]
  outfile.close()
  os.remove(my_file)
  </code></pre>
  
  <p>Here <code>my_file</code> is a variable that contains complete path structure of a file. Like wise <code>dec_file</code> also contains path, but to a new file. And the file im trying to remove is the file that's being used under <code>read mode</code>. Need some help please.</p>
  
  <p><strong><em>my try's :</em></strong></p>
  
  <ol>
  <li>Tried closing the file <code>my_file.close()</code>. The corresponding error i got was <code>AttributeError: 'str' object has no attribute 'close'</code>. I knew, when a file is in
  <code>read mode</code> it automatically closes when it comes to the end of the
  file. But still i gave it a try</li>
  <li>Also tried by <code>os.close(my_file)</code> as per <a href="https://stackoverflow.com/a/1470388/3869739">https://stackoverflow.com/a/1470388/3869739</a>. i got error as <code>TypeError: an integer is required</code></li>
  <li>Or, am i getting this error just because i have opened the file
  twice (for counting the line and to read the file content),..?</li>
  </ol>