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!
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
Maximilian HillPython Development Techdegree Student 4,967 Points
Basketball Stats Tool: Exception Handling + Dunder Main
I've been working with my app all day. I got it to work for a bit, but have been working between different IDEs so I think that's got me mixed up. I have two issues.
The first is that I cannot get my app to handle the exceptions. I'm pretty sure it has to do with indentation so can you take a look at lines 256-260 on my constants.py module?
My second problem is that I am getting a name error when trying to enact my dunder_main() saying that my overall main() call function starting on line 127 of my constant.py module is not defined.
My code is as follows: https://w.trhou.se/76v8j0j1fe
Thank you for the help!
Asher OrrPython Development Techdegree Graduate 9,252 Points
Hi Max! Let me take a stab at these:
"The first is that I cannot get my app to handle the exceptions. I'm pretty sure it has to do with indentation so can you take a look at lines 256-260 on my constants.py module?"
try: option_2 = input("Pick a team: ") if option2.isalpha() == False or len(option_2) >= 2 or option_2 in ABC:
On line 268, option2 should be option_2. You're saying "if there's an error with option2, do this!" The problem, though, is that option2 is not defined.
"My second problem is that I am getting a name error when trying to enact my dunder_main() saying that my overall main() call function starting on line 127 of my constant.py module is not defined."
First, update constant.main() in app.py. It should be constants.main() (since you're importing the constants.py file.)
- Remove the first line in constants.py (if name == "main":)
- Unindent your code accordingly (highlight it and hold down shift and tab simultaneously. You only need to unindent it once.)
- Update app.py to:
import constants if __name__ == "__main__": constants.main()
When I ran app.py, it worked for me. I would suggest reviewing the Dunder Main workshop [https://teamtreehouse.com/library/dunder-main/introduction-to-dunder-main] to understand why these changes are necessary. Let me know if you need more help!