Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 试图打开由python中相同代码写入的.bat文件时出现权限错误_Python 3.x_Batch File - Fatal编程技术网

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