__pycache__, one more good reason to stck with Python 2?

Carl Banks pavlovevidence at gmail.com
Mon Jan 17 23:40:23 EST 2011


On Jan 17, 6:29 pm, Alice Bevan–McGregor <al... at gothcandy.com> wrote:
>         find . -name \*.pyc -exec rm -f {} \;
>
> vs.
>
>         rm -rf __pycache__
>
> I do not see how this is more difficult, but I may be missing something.


Well the former deletes all the pyc files in the directory tree
whereas the latter only deletes the top level __pycache__, not the
__pycache__ for subpackages.  To delete all the __pycache__s you'd
have to do something like this:

file . -name __pycache__ -prune -exec rm -rf {} \;

or, better,

file . -name __pycache__ -prune | xargs rm -rf

Still not anything really difficult.  (I don't think a lot of people
know about -prune; it tells find don't recursively descend.)


Carl Banks



More information about the Python-list mailing list