2014-04-08 23:02:24 +01:00
|
|
|
class C:
|
|
|
|
def f():
|
|
|
|
pass
|
|
|
|
|
2014-04-08 21:32:29 +01:00
|
|
|
# del a class attribute
|
|
|
|
|
|
|
|
del C.f
|
|
|
|
try:
|
|
|
|
print(C.x)
|
|
|
|
except AttributeError:
|
|
|
|
print("AttributeError")
|
|
|
|
try:
|
|
|
|
del C.f
|
|
|
|
except AttributeError:
|
|
|
|
print("AttributeError")
|
|
|
|
|
|
|
|
# del an instance attribute
|
|
|
|
|
|
|
|
c = C()
|
|
|
|
|
|
|
|
c.x = 1
|
|
|
|
print(c.x)
|
|
|
|
|
|
|
|
del c.x
|
|
|
|
try:
|
|
|
|
print(c.x)
|
|
|
|
except AttributeError:
|
|
|
|
print("AttributeError")
|
|
|
|
try:
|
|
|
|
del c.x
|
|
|
|
except AttributeError:
|
|
|
|
print("AttributeError")
|
2018-02-07 04:44:29 +00:00
|
|
|
|
|
|
|
# try to del an attribute of a built-in class
|
|
|
|
try:
|
|
|
|
del int.to_bytes
|
|
|
|
except (AttributeError, TypeError):
|
|
|
|
# uPy raises AttributeError, CPython raises TypeError
|
|
|
|
print('AttributeError/TypeError')
|