Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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中的特定位置运行exe文件_Python_Windows_Exe - Fatal编程技术网

从Python中的特定位置运行exe文件

从Python中的特定位置运行exe文件,python,windows,exe,Python,Windows,Exe,我想创建一个python程序(我使用的是3.6.2,不过如果有更新版本的解决方案,我很乐意更新),它可以从游戏标题列表中随机选择一个游戏,并为游戏运行.exe。但是,我不知道如何从特定文件夹位置运行.exe文件,即C:Program Files基本上,您需要做的是: (您需要导入glob、random和os) 使用file\u list=glob.glob(“path/to/folder/*.exe”) 选择一个随机元素game=random.choice(文件列表) 运行它os.startfi

我想创建一个python程序(我使用的是3.6.2,不过如果有更新版本的解决方案,我很乐意更新),它可以从游戏标题列表中随机选择一个游戏,并为游戏运行.exe。但是,我不知道如何从特定文件夹位置运行.exe文件,即C:Program Files

基本上,您需要做的是: (您需要导入
glob、random和os

  • 使用
    file\u list=glob.glob(“path/to/folder/*.exe”)
  • 选择一个随机元素
    game=random.choice(文件列表)
  • 运行它
    os.startfile(游戏)
  • 因此:


    非常感谢,真的helped@ThomasWade如果我的awnser是正确的,您可以通过单击2个箭头下的复选标记来“接受”它。
    import glob
    import random
    import os
    
    file_list = glob.glob("path/to/folder/*.exe")
    game = random.choice(file_list)
    os.startfile(game)