python - How to use lambda as method within a class? -
here trying do
class baseclass(object): successify = lambda x: "<success>%s</success>" % x errorify = lambda x: "<error>%s</error>" % x def try1(self): print successify("try1") def try2(self): print self.successify("try2")
but neither of methods seem work..
>>> baseclass().try1() traceback (most recent call last): file "<stdin>", line 1, in <module> file "<stdin>", line 5, in try1 nameerror: global name 'successify' not defined >>> baseclass().try2() traceback (most recent call last): file "<stdin>", line 1, in <module> file "<stdin>", line 7, in try2 typeerror: <lambda>() takes 1 argument (2 given)
how use lambdas methods within class?
use lambda self, x: "...%s..." % x
Comments
Post a Comment