Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2006, 3:34 PM   #1
commodore
Programmer
 
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 commodore is an unknown quantity at this point
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()
I'm learning from http://www.freenetpages.co.uk/hp/alan.gauld/ but the text in there is so confusing.

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...
commodore is offline   Reply With Quote
Old Apr 30th, 2006, 3:44 PM   #2
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 4 Kaja Fumei is on a distinguished road
"__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.
Kaja Fumei is offline   Reply With Quote
Old Apr 30th, 2006, 4:46 PM   #3
commodore
Programmer
 
Join Date: Nov 2005
Location: Estonia
Posts: 97
Rep Power: 0 commodore is an unknown quantity at this point
Thank you Kaja Fumei, I understand it now.
commodore is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC