O'Reilly logo

Python GUI Programming Cookbook by Burkhard A. Meier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating self-testing code using Python's __main__ section

Python comes with a very nice feature that enables each module to self-test. Making use of this feature is a great way of making sure that changes to our code do not break existing code and, additionally, the __main__ self-testing section can serve as documentation for how each module works.

Note

After a few months or years, we sometimes forget what our code is doing, so having an explanation written in the code itself is indeed a great help.

It is a good idea to always add a self-testing section to every Python module, when possible. It is sometimes not possible, but, in most modules, it is possible to do so.

Getting ready

We will extend the previous recipe, so, in order to understand what ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required