title: Python n00b Tip
author: mazyod
category: Python
comments: true
date: 2013-12-12 01:35:14+00:00
slug: python-n00b-tip
tags: Burhan, coding, how-to, interface, learn, Programming, python, scripting, sublime, tip, tutorial, __init__, __main__
wordpress_id: 445

As I was surfing wikipedia learning about design patterns, I saw this interesting piece of code in the python example of the command design pattern:




```python
# Execute if this file is run as a script and not imported as a module 
if __name__ == "__main__": 
    light_switch = LightSwitch() 
    print("Switch ON test.") 

```




I am referring to the `if __name__ == "__main__"` thing. This is probably the most n00bish Python tip of all time, but it has always slipped my mind! I am sure I heard its purpose before... In any case, there you have it. I am sure it won't slip my mind again this time! ... I hope.





On a side note, progress on the part 4 of the map editor thing is still WIP, and coming along nicely. It will probably take a while, since it's a long one. Reading about design patterns is also urging me to write something about that, too. But, I don't know. It is covered super clearly in wikipedia.



