我有以下代码,我想从cool_function()调用somefunc()

class MyKlass:

    # This function is to be internally called only
    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")

我想打印出来的结果是:
FOODIR, FOO, FOO_NEW

怎么做?
目前它打印这个:
    tmp = self.somefunc(ixname)
NameError: global name 'self' is not defined

最佳答案

您可能需要执行以下操作:

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')

07-24 14:08