Answers for "python print exect error"

1

python except print error type

>>> try:
...     raise Exception('spam', 'eggs')
... except Exception as inst:
...     print(type(inst))    # the exception instance
...     print(inst.args)     # arguments stored in .args
...     print(inst)          # __str__ allows args to be printed directly,
...                          # but may be overridden in exception subclasses
...     x, y = inst.args     # unpack args
...     print('x =', x)
...     print('y =', y)
...
<class 'Exception'>
('spam', 'eggs')
('spam', 'eggs')
x = spam
y = eggs
Posted by: Guest on December-10-2020
-1

python try except print error

1 (x,y) = (5,0)
   2 try:
   3   z = x/y
   4 except ZeroDivisionError as e:
   5   z = e # representation: "<exceptions.ZeroDivisionError instance at 0x817426c>"
   6 print z # output: "integer division or modulo by zero"
Posted by: Guest on January-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language