Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
>>> s = "Hello"
|
||||
>>> s[0] = "h"
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "<pyshell#1>", line 1, in <module>
|
||||
s[0] = "h"
|
||||
TypeError: 'str' object does not support item assignment
|
||||
26
Task/Enforced-immutability/Python/enforced-immutability-2.py
Normal file
26
Task/Enforced-immutability/Python/enforced-immutability-2.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
>>> class Immut(object):
|
||||
def __setattr__(self, *args):
|
||||
raise TypeError(
|
||||
"'Immut' object does not support item assignment")
|
||||
|
||||
__delattr__ = __setattr__
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.value)
|
||||
|
||||
def __init__(self, value):
|
||||
# assign to the un-assignable the hard way.
|
||||
super(Immut, self).__setattr__("value", value)
|
||||
|
||||
>>> im = Immut(123)
|
||||
>>> im
|
||||
123
|
||||
>>> im.value = 124
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "<pyshell#27>", line 1, in <module>
|
||||
del a.value
|
||||
File "<pyshell#23>", line 4, in __setattr__
|
||||
"'Immut' object does not support item assignment")
|
||||
TypeError: 'Immut' object does not support item assignment
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue