开发者

Python: Unbound method

When I try to bind a method, I get an error:

Traceback (most recent call last):
  File "pygametest3.py", line 12, in <module>
    render = winback.rend()
TypeError: unbound method rend() must be called with winback instance as first argument (got nothing instead)

This is the code, up to the offending point:

import sys, pygame

pygame.init()

class winback:
    """Render the window"""
    def rend(self):
        rendsurf.fill(black)
        rendsurf.blit (landsurf, (landx,landy,640,480))
        screen.blit (rendsurf, (0,0,640,480))
        pygame.display.flip()
render = winback.rend()

Also, I'm sorry if this is blatantly obvious and not worth posting/reposting. This is my first real plunge into python, I've worked on this all day, I'm feeling kinda stupid, an开发者_StackOverflow社区d it's 12:30 in the morning.


Classes must be instantiated before a normal method on them can be called.

class Winback(object):
  def rend(self):
    ...

winback = Winback()
render = winback.rend()

Or you could use @staticmethod. But make it a module-level function instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜