dictionary inherit and method overriding

Discussion in 'Python' started by fdb, Jul 15, 2009.

  1. fdb

    fdb Guest

    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"]

    None

    As you see i get None instead of 1.

    Any solutions?

    Bye

    --
    FabioBD
     
    fdb, Jul 15, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXN0b3BoZXIgQXR0YXJk?=

    Inherit Page_Load method

    =?Utf-8?B?Q2hyaXN0b3BoZXIgQXR0YXJk?=, Feb 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,538
    =?Utf-8?B?Q2hyaXN0b3BoZXIgQXR0YXJk?=
    Feb 3, 2004
  2. chris
    Replies:
    2
    Views:
    324
    Nicodemus
    Mar 1, 2004
  3. Adonis

    Overriding Dictionary Object

    Adonis, Jul 26, 2004, in forum: Python
    Replies:
    1
    Views:
    335
    Christopher T King
    Jul 26, 2004
  4. RunThePun
    Replies:
    19
    Views:
    799
  5. Koszalek Opalek

    Overriding a class method with an object method

    Koszalek Opalek, Jul 2, 2007, in forum: Perl Misc
    Replies:
    8
    Views:
    152
    -berlin.de
    Jul 6, 2007
Loading...

Share This Page