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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -