What the F*ck Python!

 

Beginning one’s journey into the massive world of open source development can leave the best of us confused and discouraged, however, by putting forth the effort and taking the time to find the right project, anyone can find a home; a community and a purpose.

 

With the that in mind, it was no surprise to me that the first project that caught my attention on Github wasn’t a working project but instead a collection of some common and not so common exceptions and gotchas in the Python language. WTFPython is a repository dedicated to learning the inner workings of Python through short demonstrations and output explanations. This was amazing news for someone like me who already had a huge interest in the python language!

clone_wtfpython.png

So with the prospect of picking up some useful knowledge and mitigating future Phil’s headaches, the total clone number went up by one.

 

3 examples that stood out for me were:

Evaluation_time
This one tripped me up for awhile but I will admit it provides a great example of evaluation time discrepancy, the ‘in’ clause is evaluated at declaration time whether as the conditional is evaluated at runtime. To understand better what was happening I took to python’s interpreter spending a few minutes replicating and reproducing the sample output.

8_times
You can modify a list while iterating over it to some interesting effect. It will iterate eight times before stopping; eight because that’s when the container needs to resize.

Isnotis
Much like in Java, python compares either by value equality ‘==’ or reference equality ‘is’ keyword denoted. This behaviour can have an interesting effect when combined with an under the hood feature of python in which integers -5 to 256 are preemptively allocated memory. The original post has the full example and explanation.

 

In close, I would highly recommend taking a peek at this repo. It took no time to set up and jump into the well laid out and easy to understand examples. Coming to an understanding of a complicated gotcha or successfully predicting the output to a problem felt great, and the project itself requires no commitment only a passion to learn!

10/10, would clone again.

Leave a comment