python - Error calling variables from method class -
python - Error calling variables from method class -
am working on simple game/app. when phone call variable on web2py view, error:
quack= duck.quack() typeerror: unbound method quack() must called duck instance first argument (got nil instead) my codes here: in module
from gluon import * class duck(): def quack(): homecoming 'quacks duck' def walk(): homecoming 'walks person' in controller
def data_filters(): fils = duck.quack() homecoming dict(fils=fils) in view:
{{extend 'layout.html'}} {{=fils}}
typically, need create instance of class if want utilize methods.
class duck(): def quack(self): #... x = duck() fils = x.quack() however, if method doesn't need refer self or attributes of object, can mark static method , go on using duck.quack() now.
class duck(): @staticmethod def quack(): #... python python-2.7 web2py-modules
Comments
Post a Comment