How to find out the magic number for the .pyc header in Python 3
问题 Python bytecode (.pyc) files have a header that starts with a magic number that changes between Python versions. How can I (programmatically) find out that number for the current Python version in order to generate a valid header? I'm currently hard-coding the one for Python 3.7.1, but that means I now depend on a specific Python version. This answer does exactly what I want using py_compile.MAGIC , but that does not seem to exist anymore in Python 3. How can I do the equivalent in Python 3?