drachenbach drachenbach - 1 month ago 6
Python Question

Does Python cache repeatedly accessed files?

I was wondering if Python is smart enough enough to cache repeatedly accessed files, e.g. when reading the same CSV with pandas or unpickling the same file multiple times.

Is this even Python's responsibility, or should the operating system take care of it?

Answer

No, Python is just a language and doesn't really do anything on its own. A particular Python library might implement caching, but the standard functions you use to open and read files don't do so. The higher-level file-loading functions in Pandas and the CSV module don't do any caching either.

The operating system might do some caching of its own, but you can't control that from within Python.

Comments