[docs] Misleading to disparage the -b option and focus on what it does NOT do.

Douglas Morris dougbmorris at yahoo.com
Thu Aug 16 23:51:43 EDT 2018

Hello, volunteer who is working harder than me. I spent something on the order of an hour, not sure, time flies when you have no clue, trying to compile and run python 3.6 bytecode without the source code. That is possible ONLY with the -b option. I first tried what I though were more obvious possibilities.

This will NOT work:# python -OO -m compileall <package># find <package> -name \*.py -type f -execdir rm '{}' \;# python <package>.main.main()ImportError or something that says can't find whatever module or method, don't remember exactly.
Turns out I need the 'legacy' bytecode, but it's not legacy. It's currently useful as the only way to get standalone bytecode to work. Who in his right mind would try an outdated option? Not me for too long, that's who.

Here is the Standard Library documentation for the -b option, under the compileall module:-b
Write the byte-code files to their legacy locations and names, which mayoverwrite byte-code files created by another version of Python. The defaultis to write files to their PEP 3147 locations and names, which allowsbyte-code files from multiple versions of Python to coexist.

The description is more the not -b option. The emphasis on 'legacy' trivializes the option into irrelevance. Legacy code is unused, unsupported code. The -b option DOES SOMETHING IMPORTANT:-b
Write the byte-code files to their historically original filename locations (and format?), which is the only way the python interpreter will run bytecode without the concomitant presence of its source code. Without the -b option, bytecode files are written to a __pycache__ subdirectory under a version-specific filename, which allows different versions of bytecode derived from the same source to coexist in storage. For details see PEP 3147.

I am not sure if the format of the standalone bytecode uses magic number + timestamp as the 'legacy' .pyc files did per the intro of the PEP, or if that has been dropped. If not dropped, then the 'legacy' qualifier is not even partially true in any technical sense, and will remain so until the bytecode protocol is scrapped. There is no reason to consider the old way depreciated rather than specialized. It is simply not the default way but earns its keep with its complementary pros and cons.

My use case: I want to use only bytecode for a Web service. Sure, I could be doing it wrong. This is a learning experience for me all the way.

Douglas Morris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20180817/fb104969/attachment-0001.html>

More information about the docs mailing list