2015-12-10 47 views
0

所以我的代碼基本上是設計刪除一個文件,如果不正確的數據輸入。然而,它不起作用,驚喜。Win32錯誤,無法刪除文件沒有錯誤

這裏是我的刪除部分代碼:

except ValueError: 
     print("Something went wrong") 
     file = open(username + ".txt", "w") 
     file.close() 
     import os, sys 
     os.remove(username + ".txt") 
     break 

,這是我保留錯誤:

WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'newtext.txt' 

任何幫助將是巨大的感謝:d

+1

您是否使用其他地方的文件?忘了關閉它在你的代碼或其他程序的不同部分? – mirosval

回答

0

我想你已經在文字處理器如記事本中打開了文本文件。運行Python腳本時,請事先關閉文字處理器,並且代碼應該正常工作。如果這不能解決問題,請給出更多細節,我會盡力幫助您解決問題。