# Ensure variable is defined try: x except NameError: x = None # Test whether variable is defined to be None if x is None: some_fallback_operation() else: some_operation(x)
# Ensure variable is defined try: x except NameError: x = None # Test whether variable is defined to be None if x is None: some_fallback_operation() else: some_operation(x)