小编mae*_*777的帖子

如何修复“NameError: name method-name is not defined”?

我在使用以下 Python 代码时遇到问题:

class Methods:

    def method1(n):
        #method1 code

    def method2(N):
        #some method2 code
            for number in method1(1):
                #more method2 code

def main():
    m = Methods
    for number in m.method2(4):
            #conditional code goes here

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我得到

NameError: name 'method1' 未定义。

如何解决此错误?

python function nameerror

5
推荐指数
1
解决办法
8855
查看次数

标签 统计

function ×1

nameerror ×1

python ×1