__pycache__, one more good reason to stck with Python 2?
Antoine Pitrou
solipsis at pitrou.net
Wed Jan 19 13:03:23 EST 2011
On Wed, 19 Jan 2011 08:30:12 -0800 (PST)
jmfauth <wxjmfauth at gmail.com> wrote:
> Yes, I can launch a pyc, when I have a single file.
> But what happens, if one of your cached .pyc file import
> a module with a name as defined in the parent directory?
> The machinery is broken. The parent dir is not in the
> sys.path.
Well, you don't have to launch a pyc file anyway. Put all your code in
some (pyc) modules on the standard Python path, and use a clear-text
script with some trivial code to invoke a function from the compiled
modules.
Otherwise you can customize sys.path a little from your script,
using __file__ and os.path.dirname. Nothing complicated AFAICT.
(by the way, the fact that pyc files are version-specific should
discourage any use outside of version-specific directories,
e.g. /usr/lib/pythonX.Y/site-packages)
Regards
Antoine.
More information about the Python-list
mailing list