Python Cool Tricks

Nice. Some are exotic, but list comprehensions, the empty string trick are commonly handy, and the json pretty-printing maybe less so but good to know.

The note about dir() and help() are great if you’re not already familiar (you should be).

The Python enum trick is a new one by me:

class PlayerRanking:
 Bolt, Green, Johnson, Mom = range(4)
-> 4
As is the 'launch an interactive shell'
import code; code.interact(local = locals())
That beats printf-debugging by a country mile :-)
Comments (0)

Skip to main content