Why "if __name__ == '__main__':"?
#1
I've seen the line in the subject in some Addons so I just added it to mine, too.

But why do I need it? What is it meant to do? Can I just drop this "if block"?
Reply
#2
This condition usually protects module-level executable instructions and prevents side-effects when your script is imported from another script. Even if this is the main script, it may be imported, for example, from a testing suite. So it's a good habit to use this condition even though it's not strictly necessary.
Reply

Logout Mark Read Team Forum Stats Members Help
Why "if __name__ == '__main__':"?0