Python 3.x 试图打开由python中相同代码写入的.bat文件时出现权限错误
这是我的密码Python 3.x 试图打开由python中相同代码写入的.bat文件时出现权限错误,python-3.x,batch-file,Python 3.x,Batch File,这是我的密码 import webbrowser import os import time import sys stopexpexe = open('C:\\Games\\windowsexplorerstop.bat', 'w') stopexpexe.write('taskkill /F /IM explorer.exe') stopexpexe.close startexpexe = open('C:\\Games\\windowsexplorerrestart.bat', 'w')
import webbrowser
import os
import time
import sys
stopexpexe = open('C:\\Games\\windowsexplorerstop.bat', 'w')
stopexpexe.write('taskkill /F /IM explorer.exe')
stopexpexe.close
startexpexe = open('C:\\Games\\windowsexplorerrestart.bat', 'w')
startexpexe.write('start explorer.exe')
startexpexe.close
os.startfile('C:\\Games\\windowsexplorerstop.bat')
time.sleep(218)
os.startfile('C:\\Games\\windowsexplorerrestart.bat')
我得到的错误如下:“PermissionError:[WinError 32]该进程无法访问该文件,因为它正被另一个进程使用:'C:\Games\windowsexplorerstop.bat'”
我需要帮助弄清楚为什么会发生这种情况,以及如何解决它
我正在运行python 3.4.3。我是一个非常新的程序员,可能不理解更复杂更详细的帖子,所以请尽可能多地解释。我知道在这一点上我可能没有遵循某种“风格”的代码,但到目前为止我是自学成才的,所以请容忍我。我会尽力帮助解决任何进一步的问题,谢谢。
-Scott很可能您没有关闭文件
stopepexe.close
应该是stopepexe.close()
,同样,对于startexpexe.close
,您不会关闭文件stoppexe.close
应该是stoppexe.close()
,对于startexpexe.close