[Python-ideas] Add a cryptographic hash (e.g SHA1) of source toPython Compiled objects?

Brett Cannon brett at python.org
Tue Feb 3 20:59:14 CET 2009

On Tue, Feb 3, 2009 at 11:44, Raymond Hettinger <python at rcn.com> wrote:
> [Brett]
>> The only thing you need to compile bytecode is the same Python version
>> (and thus the same magic number) and whether it is a .pyc or .pyo (and
>> thus if -O/-OO was used). Your platform has nothing to do with
>> bytecode compilation.
> Well said.  The best validation of a pyc is to compile the source.

Actually, recompilation is so cheap and easy (see py_compile or
compileall with the --force flag) that bothering with the hash is
probably not worth it. Might as well recompile the thing and just see
if the strings are equivalent. Unless you are doing this for a ton of
files the speed difference, while possibly relatively huge, in
absolute terms is still really small and thus probably not worth the
added complexity of the hashes.


More information about the Python-ideas mailing list