Skip to main content
6 events
when toggle format what by license comment
Jun 28, 2021 at 16:41 vote accept Mast
Jun 12, 2021 at 1:12 comment added Peilonrayz @N3buchadnezzar I confess when I first used pathlib I did the same :) Everything and everything was pathlib, os.path no more. But I now try to use the best tool for the job rather than being a 'purist'. For example, os.path.commonprefix is pretty handy at times. Not necessarily when I'm interacting with paths mind you ;)
Jun 11, 2021 at 23:34 comment added N3buchadnezzar Makes sense =) If I am already importingpathlib I try to get the most out of it before importing os, I guess that is just a bad habit of mine. Using subprocess with pathlib usually gets the job done. Speedwise I think they are much the same.
Jun 11, 2021 at 23:29 comment added Peilonrayz @N3buchadnezzar in get_directory_size? The simple answer is because Mast was already used os.walk. The longer answer is because I prefer using os.walk when I have to recursively descend and I only want directories or files. Having to figure out which of f.is_dir(), f.is_file(), f.is_symlink(), etc I want isn't how I want to spend my time. I also don't really want to figure out if rglob walks symlinks, and if rglob does how can I stop walking symlinks? os.walk is good enough
Jun 11, 2021 at 23:19 comment added N3buchadnezzar Great answer! Just a quick comment, is there a reason you are using os.walk instead of doing something like sum(f.stat().st_size for f in path.rglob("*") if f.exists())? Cheers
Jun 11, 2021 at 21:32 history answered Peilonrayz CC BY-SA 4.0