What I mean is, if for example I get an error like
Traceback (most recent call last):
File "score_keeper-test.py", line 106, in <module>
app = program()
File "score_keeper-test.py", line 37, in __init__
self.label1.set_text(team1_name)
TypeError: Gtk.Label.set_text() argument 1 must be string, not None
Is there any way to make python print something like “You MUST enter a name in the TWO boxes” instead of the error above?
The Pythonic idiom is EAFP: easier to ask for forgiveness than permission. In this case:
Note how I explicitly catch
TypeError. This is recommended by PEP 8 — Style Guide for Python Code (essential reading for any Python programmer):An alternative (not-recommended) approach would be:
…which is an example of LBYL: Look before you leap. This style can leave your code littered in
if-statements.