简体   繁体   English

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

[英]Running an exe file from a specific location in Python

I want to create a python (I'm using 3.6.2 although if there's a solution on a newer version I'd be happy to update) program that randomly selects a game from a list of game titles and runs the.exe for the game.我想创建一个从游戏标题列表中随机选择一个游戏并运行.exe游戏。 However, I don't know how to run a.exe file from a specific folder location ie C:Program Files但是,我不知道如何从特定文件夹位置运行 a.exe 文件,即 C:Program Files

Basically what you need to do is: (You need to import glob, random and os )基本上你需要做的是:(你需要导入glob, random and os

  1. Find all.exe in the folder with file_list = glob.glob("path/to/folder/*.exe")file_list = glob.glob("path/to/folder/*.exe")的文件夹中查找 all.exe
  2. Select a random element game = random.choice(file_list) Select 随机元素game = random.choice(file_list)
  3. Run it os.startfile(game)运行它os.startfile(game)

So:所以:

import glob
import random
import os

file_list = glob.glob("path/to/folder/*.exe")
game = random.choice(file_list)
os.startfile(game)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM