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

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


On Jan 17, 10:17 am, jmfauth <wxjmfa... at gmail.com> wrote:
> > No, I'm sorry, they're not obvious at all.
>
> These reasons become obious as soon as you start working.
>
> Let's take a practical point view. It did not take a long time
> to understand, that it is much simpler to delete the __pycache__
> directory everytime I compile my scripts than to visit it just
> because I deleted or renamed a .py file in my working directory.

According to PEP 3147, stale *.pyc files in the __pycache__
directories are ignored.  So it's no longer necessary to delete the
*.pyc files when renaming a *.py file.  This is a big improvement, and
easily justifies __pycache__ IMO, even without the distro
considerations.


> How long will it take to find on the web tools to parse and
> delete ophan .pyc files on a hd?

Probably under a month.  (Updating old tools to work with new scheme
will take a bit longer.)


> If I get (stupidly, I agree) a .pyc file and want to test
> it. Should I create manually a cache alongside my test.py
> script?

Nope: according to PEP 3147 a standalone *.pyc should not be put in
same directory where the source file would have been, not in the
__pycache__ directory (it'll be considered stale otherwise).

It says this is for backwards compatibility, but I think there are
valid reasons you don't want to deliver source so it's good that we
can still do that.


> If I wish to delete the numerous auxiliary files a TeX
> document produces, I just del /rm .* to keep a clean working
> dir. With Python now? Impossible! The files are spread in two
> dirs (at least).
>
> ...
>
> That's life, unfortunately.

Give yourself a little time.

The one little non-temporary drawback I see for __pycache__ is if you
have a directory with lots of stuff and one or two python files in the
mix; and then you add that directory to sys.path and import the
files.  It creates the __pycache__ in that directory.  It's a bit of a
shock compared to the *.pyc files because it's at a very different
place in the listings, and is a directory and not a file.  But that's
a minor thing.


Carl Banks



More information about the Python-list mailing list