使用os.system打开列表中的文件

时间:2017-03-01 16:26:06

标签: python-3.x os.system

我正在尝试从我在Python3中生成的列表中打开一个随机文件。

import random
BL = ["0.jpg","1.jpg","2.jpg","3.jpg"]
secure_random = random.SystemRandom()
a = secure_random.choice(BL)
os.system('open ./a')

我收到错误:

The file /pathtofile/a does not exist.
256

非常感谢任何帮助!!

1 个答案:

答案 0 :(得分:0)

只需将最后一行更改为:

os.system('open ./{}'.format(a))