Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从传递相同参数类的function1(x)调用function2(x)?_Python_Function_Class - Fatal编程技术网

Python 从传递相同参数类的function1(x)调用function2(x)?

Python 从传递相同参数类的function1(x)调用function2(x)?,python,function,class,Python,Function,Class,当我调用myClass_instance.myProceduresecondVar时,我得到一个错误,它表示: class myClass(object): def __init__(self, firstVar): ''' Some docstring ''' self.var = firstVar def myProcedure1(self, secondVar): ''' S

当我调用myClass_instance.myProceduresecondVar时,我得到一个错误,它表示:

class myClass(object):
    def __init__(self, firstVar):
        '''
        Some docstring
        '''
        self.var = firstVar


    def myProcedure1(self, secondVar):
        '''
        Some docstring1
        '''
        return my_thing

    def myProcedure(self, secondVar):
        '''
        Some docstring2
        '''

        what_I_Need = myClass.myProcedure1(secondVar)
        do something with this
        return something else

如何传递secondVar使其生效?

您直接在未绑定的类上调用该方法。这意味着没有传入self,而secondVar被解释为self的值

在self上调用该方法:


self在这里只是对实例的另一个引用,就像调用myProceduce时myClass_实例一样。。。关于这个问题。

这是一个相当基本的问题,尽管我找不到关于这个问题的现有答案!你必须构造一个类的实例来调用实例方法。那么你的观点是什么???我确实在寻找答案,但答案并不在这么多问题中!!!这是否意味着只有像殿下这样的“专家”才能提出这样的问题?为什么你不让你的知识对别人有用呢?就像你是一个编程新手而不是扮演全能者时别人对你有用一样。如果你这么优秀,为什么其他拥有59倍以上声誉的程序员会花时间回答这个问题呢。你认为你是一个很好的人,但你只是有一点。。。。。某物但你的回答还是错了
TypeError: myProcedure1() missing 1 required positional argument: 'secondVar'
self.myProcedure1(secondVar)