Problems with code

Albert Hopkins marduk at letterboxes.org
Mon Mar 30 12:25:44 EDT 2009


On Mon, 2009-03-30 at 11:05 -0500, Zach Goscha wrote:
> Hi,
>  
> I am trying to call an unbound method (Map.Background) but getting the
> following error:
>  TypeError: unbound method background() must be called with Map
> instance as first argument (got nothing instead)
>  
> Here is some of the code(not completed) 
>  
> Thanks in Advance
> - Zach
>  
>  
> Code:
> 
> class Knight(games.Sprite):
>     """ A moving knight. """
>     SWORD_DELAY = 50
>     sword_wait = 0
>         
>         
>     def update(self):
>         """ moving knight based on keys pressed. """
>  
>         if games.keyboard.is_pressed(games.K_w):
>             self.y -= 3
>             self.angle = 0
>         if games.keyboard.is_pressed(games.K_s):
>             self.y += 3
>             self.angle = 180
>         if games.keyboard.is_pressed(games.K_a):
>             self.x -= 3
>             self.angle = 270
>         if games.keyboard.is_pressed(games.K_d):
>             self.x += 3
>             self.angle = 90
>  
>         if self.top > games.screen.height:
>             self.bottom = 0        
>  
>         if self.bottom < 0:
>             self.top = games.screen.height
>             Map.background()
>  
>         if self.left > games.screen.width:
>             self.right = 0
>  
>         if self.right < 0:
>             self.left = games.screen.width
>  
> class Map(games.Sprite):
>  
>     def background(self):
                     ^^^^
>         new_back = games.load_image("map3.jpg",
> transparent = False)
>         games.screen.background = new_back

'self' implies that this is an instance method.  If this is not an
instance method then don't use self.


If what you want is a static method (or class method) then use the
staticmethod (or classmethod) function or decorator.

I.e.

    @staticmethod
    def background():
        ...


>   
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list