python 3 replacement for dircache?

RonJohn

Before I go reinventing the wheel, can anyone tell me if there's a drop-in (or semi-drop-in) replacement for the single-line statement:

allfiles = dircache.listdir('.')
viraptor

One line? No. But you can just do:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related