python 3 替代 dircache?

标签 python python-2.7 python-3.x

在我开始重新发明轮子之前,谁能告诉我是否有单行语句的直接(或半直接)替代:

allfiles = dircache.listdir('.')

最佳答案

一行?不,但你可以这样做:

global_cache = {}
def cached_listdir(path):
    res = global_cache.get(path)
    if res is None:
        res = os.listdir(path)
        global_cache[path] = res
    return res

关于python 3 替代 dircache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32622596/

相关文章:

python - 如何在 NLTK 词性 (POS) 标记中仅获取所选标记的单词?

python - 如何在for循环python中跳过AttributeError并继续循环

python-2.7 - pip升级pyzmq时gcc失败

Python DNS模块导入错误

python - 比较行时如何绘制条形图?

python - 使用 self 时缺少 1 个必需的位置参数

python - Canvas 文本更新 - Python3 Tkinter

python - 我们可以将 html 标签包含到 AIML 文件的 <template> 中吗

python - 根据条件Python对多行进行分组/求和

python - Pandas 数据帧 to_latex : how to fit tables on a page?