For Python 2.6 and later and Python 3.x:
except Exception as e: print(e)
For Python 2.5 and earlier, use:
except Exception,e: print str(e)
More Related Contents:
- I’m getting an IndentationError. How do I fix it?
- Why is “except: pass” a bad programming practice?
- How to print an exception in Python?
- “Inner exception” (with traceback) in Python?
- Log exception with traceback in Python
- Print an error message without printing a traceback and close the program when a condition is not met
- Manually raising (throwing) an exception in Python
- Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”
- django MultiValueDictKeyError error, how do I deal with it
- live output from subprocess command
- When I catch an exception, how do I get the type, file, and line number?
- How to retry after exception?
- Python giving FileNotFoundError for file name returned by os.listdir
- Cost of exception handlers in Python
- SyntaxError inconsistency in Python?
- Why return NotImplemented instead of raising NotImplementedError
- How to handle exceptions in a list comprehensions?
- Bad idea to catch all exceptions in Python
- How to get exception message in Python properly
- threading ignores KeyboardInterrupt exception
- How can I make silent exceptions louder in tkinter?
- Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?
- Hide traceback unless a debug flag is set
- hasattr() vs try-except block to deal with non-existent attributes
- How to re-raise an exception in nested try/except blocks?
- Python FAQ: “How fast are exceptions?”
- How to return a custom 404 Not Found page using FastAPI?
- Re-raise exception with a different type and message, preserving existing information
- Catching exception in context manager __enter__()
- Multiple try codes in one block