2010-04-29 34 views
12

tengo simple script en Python, 'first.py':Ejecutar archivo python: ¿qué función es main?

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

firstFunctionEver() 

que desee llamar a este script usando: python first.py y tienen que llamar al firstFunctionEver(). Pero, el script es feo: ¿a qué función puedo poner la llamada en firstFunctionEver() y ejecutarla cuando se carga el script?

+0

https://stackoverflow.com/questions/419163/what-does-if-name-main-do –

Respuesta

31
if __name__ == "__main__": 
    firstFunctionEver() 

Leer más en los documentos here.

9
if __name__ == '__main__': 
    firstFunctionEver() 
+0

¿Qué es '__name__' y cuándo es' __main__'? Por favor explique y proporcione referencias. – agf

Cuestiones relacionadas