我在指定目录中有一个文件夹,其中包含几个需要随机打开的PNG .我似乎无法开始random.shuffle处理该文件夹.到目前为止,我已经能够print获得内容,但它们也需要随机化,因此当它们打开时,序列是唯一的.
这是我的代码:
import os, sys
from random import shuffle
for root, dirs, files in os.walk("C:\Users\Mickey\Desktop\VisualAngle\sample images"):
for file in files:
if file.endswith(".png"):
print (os.path.join(root, file))
Run Code Online (Sandbox Code Playgroud)
这将返回文件夹中的图像列表.我想也许我可以以某种方式随机输出print然后使用open.我到目前为止失败了.有任何想法吗?