python - Calling function from another staticmethod function within a class -
i have following code, cool_function()
i'd call somefunc()
class myklass: # function internally called def somefunc(self,text): return (text + "_new") @staticmethod def cool_function(ixdirname, ixname): tmp = self.somefunc(ixname) print ixdirname, ixname, tmp return tmp = myklass.cool_function("foodir","foo")
the result want print out is:
foodir, foo, foo_new
what's way it? prints this:
tmp = self.somefunc(ixname) nameerror: global name 'self' not defined
you may want this:
class myclass: @staticmethod def somefunc(text): return text + '_new' @staticmethod def cool_function(ixdirname, ixname): tmp = myclass.somefunc(ixname) print((ixdirname, ixname, tmp)) return myclass.cool_function('foodir', 'foo')
Comments
Post a Comment