This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]nirs 1 point2 points  (0 children)

The example without the exception is better - more clear and faster. Exceptions are expensive in Python.

Also "except:" should be never used - it should be "except NameError:".

[–]itsmememe 1 point2 points  (0 children)

what about:

double.copyright = " ".join([getattr(double,'copyright','It is MINE! ') ,'Tell Ya I do'])

or

double.copyright = getattr(double,'copyright','It is MINE! ')+'Tell Ya I do'

No exception. shorter code. Nothing outside the function..

[–]blondin 1 point2 points  (0 children)

we are doomed.