[Tutor] inheritance and super() function in python

2014-04-22 Thread Jorge Leon
Good day,


I have programmed a base class for an environment I have with no problem,
but when it comes to referencing the base class's constructor in the
derived class's constructor I have been getting errors:

*TypeError: Error when calling the metaclass bases*
*module.__init__() takes at most 2 arguments (3 given)*

Here's how my base class' constructor looks like (position =  [x, y, z]):
*class Obstacle:*
*def __init__(self,position):*
*self.position = position*

Here's how my derived class's constructor looks like

*class Cylinder(Obstacle):*
*   def __init__(self,position, height, radius):*
*   super(Obstacle,self).__init__(position)*

I have no idea where the 3 given arguments are being taken from. I have
modified the code on the super line just in case I missed something but
that has not changed a thing. I have read that in Python you may be able to
double reference, but there are no other classes interfacing the base and
derived class.

If anyone has had some prior experience with this I'd appreciate your
input.

Regards,


Jorge
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] inheritance and super() function in python

2014-04-22 Thread Jorge Leon
Thank you Steve and Dave for the prompt response and advise, and sorry
about the format.

The version of Python I'm working under is 2.7.5. About the .super():
I'm going to try out the format you gave me for the files, and yes:
that's exactly how I had it. Something that has stuck from all the C++
programming I'm doing, which also leads me to believe that it may be
better for me to step away from using .super() if I don't get the
program to work as intended when I apply your advise.

Going to consult more tutorials from the page about inheritance and
operator and function overloading.

Regards,


Jorge


On Tue, Apr 22, 2014 at 3:54 PM, Dave Angel  wrote:
> Jorge Leon  Wrote in message:
>>
>
> I think Steven has nailed your main problem,  but I have two other
>  suggestions:
>
> Use text mail, not html.  This is a text list, and it can make a
>  difference in half a dozen ways. Any decent email program has a
>  way to select that.
>
> When showing an error,  include the whole traceback.  Steven would
>  not have had to guess if you had. The file names would show
>  him/us for sure.
>
> --
> DaveA
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] inheritance and super() function in python

2014-04-23 Thread Jorge Leon
>  class Cylinder(Obstacle):
>def __init__(self,position, height, radius):
>super(Obstacle,self).__init__(position)
>
> But it looks to me like the last line should be
> super(Cylinder, self).__init__(position)
>

Hey, thanks again for the help and sorry about all the format errors I
was able to successfully use super(). The classes were made with the
old style (thanks Steve for the blog post). Using the last bit of
corrections the program successfully sourced the constructor from the
parent class.

Again, thank you for the prompt and professional response.

Jorge
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor