我目前正在尝试让Python使用Subprocess从D:/ My Games运行.exe。目的很简单,只需运行所选的游戏。我正在使用的代码,当我尝试访问我的C:驱动器时工作,但是在尝试访问我的D:驱动器时出现错误。 “错误表超出范围”是我得到的错误。 任何人都知道如何从Python中访问此驱动器?
import wx
import subprocess
import os
GamesList=(os.listdir('D:\\My Games\\'))
for item in GamesList:
if str(item) == 'desktop.ini':
GamesList.remove(item)
class MainMenu(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,"Games List", size=(550,400))
panel=wx.Panel(self)
GameBox = wx.ListBox(panel, -1,(407,5),(122,350),GamesList,wx.LB_SINGLE)
GameBox.Bind(wx.EVT_LISTBOX, OnGameSelection)
def OnGameSelection(Event):
GameBox = Event.GetEventObject()
GameIndex = GameBox.GetSelection()
SelGame = GamesList[GameIndex]
subprocess.call(['D:\\My Games\\'+ SelGame + '\\' + SelGame + '.exe'])
if __name__=='__main__':
app=wx.PySimpleApp()
frame=MainMenu(parent=None,id=-1)
frame.Show()
app.MainLoop()