Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ashley Keeling
11,476 Pointswhen do you use __main__ ?
i get what it does but i am not sure when you would use this could you give me an example please ?
2 Answers
Steven Parker
243,656 PointsA common use would be to test if the code is being run as a program or if it is being included as a module in another program:
if __name__ == "__main__":
# stuff to do only if this running as a program
There was a workshop released recently you may enjoy called Understanding Dunder Main (__main__).
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsYou might want to watch this workshop