在Python中自动创建一个列表
这个问题在这里已经有了答案:
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/20051.html