Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run python file -- what function is main?

Tags:

python

I have simple python script, 'first.py':

#first.py
def firstFunctionEver() :
    print "hello"

firstFunctionEver()

I want to call this script using : python first.py and have it call the firstFunctionEver(). But, the script is ugly -- what function can I put the call to firstFunctionEver() in and have it run when the script is loaded?

like image 906
atp Avatar asked Apr 29 '10 01:04

atp


1 Answers

if __name__ == "__main__":
    firstFunctionEver()

Read more at the docs here.

like image 82
Steve Tjoa Avatar answered Sep 20 '22 15:09

Steve Tjoa