main in Python

Tim timlee126 at yahoo.com
Fri Jul 10 17:52:09 EDT 2009


Hi,
I learned that a Python script is written in this way:
def main():
    ...
if __name__ == "__main__":
    main()

Today, when I read a script, I found it has a different way:

def main():
    ...

main()

It can run as well. Can someone explain why and the rules that Python scripts get run?

Thanks and regards,
Tim


      



More information about the Python-list mailing list