![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0
![]() |
What is this 'if __name__ == '__main__'' thing?
I have been learning python. I learned a hard thing (for me) and I basically understood it all, but the very last thing confuses me to frustration. What does this do:
if __name__ == '__main__':
main()It's a bit hard to learn all this when I'm so small, don't have anything in my own language, have all these things around me disturbing... |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 4
![]() |
"__name__" is a special Python variable that has the value "__main__" if the Python file is run directly. This allows the file to be used as a Python module (i.e., with "import") without invoking its main program. This can also be used to invoke unit testing.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0
![]() |
Thank you Kaja Fumei, I understand it now.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|