Skip to content

Instantly share code, notes, and snippets.

@Daetalus
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daetalus/ec5034f08f597fee00de to your computer and use it in GitHub Desktop.
Save Daetalus/ec5034f08f597fee00de to your computer and use it in GitHub Desktop.
Inconsistent error message in Python?
# New style class
class B(object):
def __init__(self, n):
self._n = n
c = B(3)
d = B(4)
try:
print(pow(c, d))
except Exception as e:
print type(e), e.message
try:
print(pow(c, d, d))
except Exception as e:
print type(e), e.message
# will out put:
# <type 'exceptions.TypeError'> unsupported operand type(s) for ** or pow(): 'B' and 'B'
# <type 'exceptions.TypeError'> unsupported operand type(s) for pow(): 'B', 'B', 'B'
# Change it to old style class
class B:
def __init__(self, n):
self._n = n
c = B(3)
d = B(4)
try:
print(pow(c, d))
except Exception as e:
print type(e), e.message
try:
print(pow(c, d, d))
except Exception as e:
print type(e), e.message
# will out put:
# <type 'exceptions.TypeError'> unsupported operand type(s) for ** or pow(): 'instance' and 'instance'
# <type 'exceptions.AttributeError'> B instance has no attribute '__pow__'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment