On Mon, Jan 20, 2014 at 02:42:57AM -0800, Albert-Jan Roskam wrote: > Hi, > > > When is setting a PYTHONDONTWRITEBYTECODE environment variable useful? Or set > sys.dont_write_bytecode to True? Or start Python with the -B option? > I know what it does > (http://docs.python.org/2/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE), > i.e. no pyc or pyo fiules are written, but WHY is that sometimes a good > thing? The only useful scenario I can think of is when you don't have write > rights to create pyc files but you want to use a package anyway.
If you don't have write permissions then it won't write the byte code files anyway. > Perhaps related: it is possible to import zip files, but no pyc files will be > created when you do this. However, I recently opened an EGG file with a zip > utility (because I knew egg uses zipimport so it's a zip-like format) and I > noticed that there were .pyc files. If the creator of the egg put them there, > they'd only be useful if the user uses the exact same Python implementatiopn > and version, right? So hoiw can the be there? The .pyc files will be ignored if the versions don't match. One problem that can occur with the byte-code files is if you try to import them using different interpreters at different times. So let's say you have a module that is regularly imported by Python 2.6 and then you also want to use it in a program that you regularly run with Python 2.7. The two interpreters will fight each other constantly rewriting and stomping over each other's .pyc files. You could use the -B option with one of the interpreters to alleviate this. Truthfully I've never used the option so I'm just guessing though. And in any case Python 3 handles the multiple interpreters problem better with its __pycache__ directory. Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor