Today we’re going to talk about a little-known fact that has been causing headaches for Windows XP users since the dawn of time (or at least 2009). It’s all about those ***** .pyc files and how they behave on our favorite operating system.
First, let’s start with some background information. When you run a Python script, it gets compiled into an intermediate bytecode file called a .pyc file. This allows for faster execution times because the code doesn’t have to be parsed every time you run it. However, on Windows XP (and earlier versions), there was a bug that caused these files to become “broken” and not get overwritten when changes were made to the original Python script.
This led to some pretty frustrating situations where users would make updates to their code but see no change in behavior because the .pyc file wasn’t being updated. To fix this, you had to manually delete the broken .pyc files and run your script again. Not exactly a great user experience!
Fast forward to 2012 when Python developer Kevin Chen submitted a patch that addressed this issue by ensuring that .pyc and .pyo files were created with write-accessible permissions on Windows, just like they are on other operating systems. This fix was included in the 2.7 release of Python and has been working great ever since!
In case you missed it earlier, Nick Coghlan (a fellow Python developer) decided to simplify Kevin’s patch by creating .pyc files with user-write permissions set from the get-go. This didn’t weaken security because any attacker running with your privileges could already change those permissions anyway!
pyc file behavior on Windows XP has finally come to a close (or at least until the next bug is discovered). And thanks to Kevin Chen and Nick Coghlan for their contributions in making this issue a thing of the past.
Now, if you’ll excuse me, I have some Python scripts to run!