知乎专栏 | 多维度架构 |
目录
import os path = "/etc" files = [] for name in os.listdir("/etc/"): if os.path.isfile(os.path.join(path, name)): files.append(name) print(files)
随机抽取一个文件
import os from random import choice path = "/etc" files = [] for name in os.listdir("/etc/"): if os.path.isfile(os.path.join(path, name)): files.append(name) file = choice(files) print(file)