📜  使用 os.listdir 在 python 中选择随机 img - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:41.203000             🧑  作者: Mango

代码示例1
import random, os
path = r"C:\Users\G\Desktop\scientific-programming-2014-master\scientific-programming-2014-master\homework\assignment_3\cifar-10-python\cifar-10-batches-py"
random_filename = random.choice([
    x for x in os.listdir(path)
    if os.path.isfile(os.path.join(path, x))
])
print(random_filename)