[Tutor] inheritance, python and pygame

rail shafigulin rail.shafigulin at gmail.com
Tue Oct 11 20:08:25 CEST 2011


On Tue, Oct 11, 2011 at 10:56 AM, Hugo Arts <hugo.yoshi at gmail.com> wrote:

> On Tue, Oct 11, 2011 at 4:20 PM, rail shafigulin
> <rail.shafigulin at gmail.com> wrote:
> > i'm trying to learn OOP, python and pygame at the same time. so far it
> has
> > been ok, but i stumbled onto a problem
> >
> > here is the code that causes problems
> >
> > #!/usr/bin/python3.1
> > import pygame
> > pygame.init()
> >
> > class BaseSprite(pygame.sprite.Sprite):
> >   def __init(self, imagefile):
> >     super(type(self), self).__init__()
> >     self.image = pygame.image.load(imagefile)
> >     self.image = self.image.convert()
> >     self.rect = self.image.get_rect()
> >
> > class Cloud(BaseSprite):
> >   """
> >   cloud sprite
> >   scrolls down and moves side to side when it is reset
> >   """
> >   IMAGE = 'cloud.gif'
> >   def __init__(self):
> >     super(type(self), self).__init__(type(self).IMAGE)
> >
> > def main():
> >   cloud = Cloud()
> >
> > if __name__ == '__main__':
> >   main()
> >
>
> Well, for one, you misspelled __init__ in the BaseSprite class above
> (you have it written as __init). That means that method won't be
> called at all, which is likely what is causing problems.
>
> Also, when using python3, you don't need to specify any arguments to
> super. Just calling super() will work.
>
> Hugo
>
my apologies for not writing and reading my own code correctly. Hugo you
were correct, once i fixed the spelling error it all worked. and thanks for
the hint on how to use super() in python3.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111011/08a31060/attachment.html>


More information about the Tutor mailing list