Only this! I'm going crazy!
Than you!
Code:
class myDict(dict):
def __getitem__(self, y):
print("Doing something")
return dict.__getitem__(self, y)
a=myDict()
a["value"] = 1
print a["value"]
Christian Heimes ha scritto:
> How about returning the value? :]
--
FabioBD
-
fdb wrote:
> Hi all,
>
> I need to extend and not replace the __getitem__ method of a dict class.
>
> Here is sample the code:
>
class myDict(dict):
> def __getitem__(self, y):
> print("Doing something")
> dict.__getitem__(self, y)
>
a=myDict()
>
Hi all,
I need to extend and not replace the __getitem__ method of a dict class.
Here is sample the code:
>>> class myDict(dict):
... def __getitem__(self, y):
... print("Doing something")
... dict.__getitem__(self, y)
...
>>> a=myDict()
>>> a["value"] = 1
>>> print a["value"