#1
  1. living person
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    South Africa
    Posts
    123
    Rep Power
    14

    Super class methods


    Hey Im quite new to python. Ive created a derived class, and I have overridden one of the super class' methods, but I also want to call the super class' method (kind of adding to it).

    I think thats working. The super class' method calls another method which i've overridden normally. It returns a list. But I get an error:
    ValueError: Too many values to unpack

    what does that mean?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Well, you get this error if you try something like this:
    Code:
    a,b = [1,2,3]  # -> error
    a,b,c = [1,2,3]  # -> no error ;)
    Regards, mawe

    Comments on this post

    • CyBerHigh agrees
    • netytan agrees : :)
  4. #3
  5. living person
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    South Africa
    Posts
    123
    Rep Power
    14

    Thanks


    Thanks,

    yeah, i realised that the superclass method is calling one of its other methods.
    The superclass' method does stuff and calls another one of its methods (that is must be overridden by a subclass). So I i've overridden it in my subclass, but when I call the superclass' method, it does the work and then calls its other method (which just returns an error string) instead of calling my overridden method. arghh!

    Code:
    class SuperClass:
      def meth1(this):
        ...
        [a,b] = meth2(a,b)
    
      def meth2(this,a,b):
        return "Unimplemented method meth2"
    
    class SubClass(SuperClass):
      def meth1(this):
        ...
        SuperClass.meth1(this)
    
      def meth2(this,a,b):
        return [a+"bla",b+10]
    
    obj = SubClass(...)
    obj.meth1()
    When I hadn't overridden meth1, and just used the inherited meth1 it worked fine and called the overridden meth2(in SubClass), but now that I've overridden meth1 (and called its super version) it calls SuperClass' meth2 instead of SubClass'.

    Is there a way of getting meth1, to call meth2 in the subclass. Am I going wrong somewhere? I'm not really able to change SuperClass.meth1
  6. #4
  7. living person
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    South Africa
    Posts
    123
    Rep Power
    14

    DON't WORRY


    nevermind,

    made a very stupid mistake in my code.

    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo