if result is None:
print “error parsing stream”
elif result:
print “result pass”
else:
print “result fail”
keep it simple and explicit. You can of course pre-define a dictionary.
messages = {None: ‘error’, True: ‘pass’, False: ‘fail’}
print messages[result]
If you plan on modifying your simulate function to include more return codes, maintaining this code might become a bit of an issue.
The simulate might also raise an exception on the parsing error, in which case you’d either would catch it here or let it propagate a level up and the printing bit would be reduced to a one-line if-else statement.
Don’t fear the Exception! Having your program just log and continue is as easy as:
try:
result = simulate(open(“myfile”))
except SimulationException as sim_exc:
print “error parsing stream”, sim_exc
else:
if result:
print “result pass”
else:
print “result fail”
# execution continues from here, regardless of exception or not
And now you can have a much richer type of notification from the simulate method as to what exactly went wrong, in case you find error/no-error not to be informative enough.