2

Can someone help to say, how to view the definition of dict.__getitem__() method?

blhsing
  • 91,368
  • 6
  • 71
  • 106
VISHBALA
  • 87
  • 1
  • 1
  • 5

1 Answers1

3

dict.__getitem__() is a built-in method implemented in C, the source of which can be found in CPython's PyDict_GetItem function: https://github.com/python/cpython/blob/796cc6e3ad3617c1ea9e528663aac1a206230a28/Objects/dictobject.c#L1349

blhsing
  • 91,368
  • 6
  • 71
  • 106
  • Thanks , it helped. – VISHBALA Apr 01 '19 at 17:29
  • can you also help to find the python definition of the same dict __getitem__() method – VISHBALA Apr 01 '19 at 17:30
  • Glad to be of help. There is no Python definition of `dict.__getitem__` because it is purely implemented in C. – blhsing Apr 01 '19 at 17:31
  • ok, so what if i want to override the the same method by inheriting dict into my class , how would i do that – VISHBALA Apr 01 '19 at 17:42
  • There are many examples if you do a search with keywords "python dict subclass". For example, https://stackoverflow.com/questions/2390827/how-to-properly-subclass-dict-and-override-getitem-setitem – blhsing Apr 01 '19 at 17:49