Automatically creating a list in Python
This question already has an answer here:
import glob
my_new_list = glob.glob("/your/folder/*")
你也可以使用os
:
import os
from random import shuffle
# Base directory from which you want to search
base_dir = "/path/to/whatever"
# Only take the files in the above directory
files = [f for f in os.listdir(base_dir)
if os.path.isfile(os.path.join(base_dir, f))]
# shuffle (in place)
shuffle(files)
链接地址: http://www.djcxy.com/p/20052.html
下一篇: 在Python中自动创建一个列表