try: myVar except NameError: myVar = None # or some other default value. # Now you're free to use myVar without Python complaining.