on-internet
← Community

pathlib.Path quite slow

Stack Overflow ·

pathlib.Path appears to run much slower than I had hoped for. The following function deletes .pyc files older than that of the filename passed in as a parameter. Is there a faster alternative way of doing this. import time from pathlib import Path def stale_pyc_del(path: str) -> None: spd_start = time.perf_counter() cur_import = Path(path).resolve() if Path.is_dir(cur_import): cutoff_time = float('+inf') pycache_dir = cur_import / "__pycache__" else: # file not directory cur_file = Path(__file__).resolve() cutoff_time = max(cur_file.stat().st_mtime, cur_import.stat().st_mtime) pycache_dir = cu

Comments

Sign in or sign up to comment and upvote.

No comments yet.