title: How to tackle this python error - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
body: <p>I am trying to transfer the content of the file ‘A’ into ‘temp’ file with the help of ‘shutil’ module. But, I am getting below error:</p>
  
  <pre><code>[WinError 32] The process cannot access the file because it is being used by another process
  </code></pre>
  
  <p>I also tried to research in google for the same error, however none of them helped me. I am not sure what is going wrong.</p>
  
  <p>I am using windows 10 (64 bit), my python version is 3.7.</p>
  
  <p>The details of the coding are as follows:</p>
  
  <pre><code>    import csv
      import shutil
      from tempfile import NamedTemporaryFile
      import os
  
      class csvtest():
  
          def editcsv1(self,filename):  
              filename="data.csv"
              tempfile=NamedTemporaryFile(delete=False,dir=r"C:\Users\Sahil\Desktop\python")
              with open(filename,"r") as csvfile2,open(tempfile.name,"w") as temp_file:
              reader=csv.reader(csvfile2)
              writer=csv.writer(temp_file)
  
              for row in reader:
                  writer.writerow(row)
                  csvfile2.close()
                  temp_file.close()
                  os.unlink(temp_file.name)
              shutil.move(temp_file.name,filename)
  
      abc=csvtest()
      abc.editcsv1(filename)
  </code></pre>
  
  <p>'''</p>
  
  <p>As requested, the traceback message as below :
  '''</p>
  
  <p>runfile('C:/Users/Sahil/Desktop/python/stackoverflow5may.py',wdir='C:/Users/Sahil/Desktop/python')</p>
  
  <p>File "", line 1, in 
  runfile('C:/Users/Sahil/Desktop/python/stackoverflow5may.py', wdir='C:/Users/Sahil/Desktop/python')</p>
  
  <p>File "C:\Users\Sahil\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
  execfile(filename, namespace)</p>
  
  <p>File "C:\Users\Sahil\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
  exec(compile(f.read(), filename, 'exec'), namespace)</p>
  
  <p>File "C:/Users/Sahil/Desktop/python/stackoverflow5may.py", line 23, in 
  abc.editcsv1(filename)</p>
  
  <p>File "C:/Users/Sahil/Desktop/python/stackoverflow5may.py", line 20, in editcsv1
  shutil.move(temp_file.name,filename)</p>
  
  <p>File "C:\Users\Sahil\Anaconda3\lib\shutil.py", line 578, in move
  os.unlink(src)</p>
  
  <p>PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\Sahil\Desktop\python\tmp2gibk4eh'</p>
  
  <p>'''</p>