How do I declare main code to execute in python?

ijcidjjr report abuse

I studied C++ and Java and there are structures like: 'public static void main' in which all the main code is being executed when you call the class. Is there an analog to that in python?


WKhan04 report abuse

In a python .py script each line of code is being when the script is loaded(this means the code will be executed when the script is imported to another script). If you want the code to be executed only when you call the script directly(e.g. "python") then create following block inside if __name__ == "__main__":

Add Answer

Need support?

Just drop us an email to ... Show more