In this post I’d like to briefly mention a Python nicety:
If you haven’t seen this before, that’s how a Python script checks if it’s been executed from the command-line, rather than just imported by another script.
Every line of code within the condition is only executed when the script is executed:
and not when the script is just imported:
This way, you can distinguish between just importing your predefined methods and variables and actually executing your script using said methods and variables. Handy!
📬 Subscribe to my newsletter
Get notified of my latest articles by providing your email below.