Python,错误:“未定义函数”,

sh

我有2个@classmethod:其中一个是“操作员”,另一个是“ pretty_print_2”。在“操作员”中,我需要调用“ pretty_print_2”。

第一种方法如下:

    @classmethod
def operators(cls, operator_filter=None, limit_filter=0, ncores=1, exec_mode='sync'):


    ...

    response = None
    try:
        if Cube.client is None:
            raise RuntimeError('Cube.client is None')

        query = 'oph_operators_list '

        if operator_filter is not None:
            query += 'operator_filter=' + str(operator_filter) + ';'
        if limit_filter is not None:
            query += 'limit_filter=' + str(limit_filter) + ';'
        if ncores is not None:
            query += 'ncores=' + str(ncores) + ';'
        if exec_mode is not None:
            query += 'exec_mode=' + str(exec_mode) + ';'

        if Cube.client.submit(query) is None:
            raise RuntimeError()

        if  Cube.client.last_response is not None:
            response = Cube.client.deserialize_response()


    except Exception as e:
        print(get_linenumber(), "Something went wrong:", e)
        raise RuntimeError()
    else:

        cls.pretty_print_2(response)

第二种方法如下:

@classmethod
def pretty_print_2(response):

但是当我运行脚本时,遇到以下错误:

 cls.pretty_print_2(response)
TypeError: pretty_print_2() takes 1 positional argument but 2 were given

如有任何建议,我将不胜感激。谢谢你。

安吉·贾斯瓦尔(Ankit Jaiswal)

类方法中的第一个参数应为cls,即类本身。所以你的方法:

@classmethod
def pretty_print_2(response)

应该看起来像:

@classmethod
def pretty_print_2(cls, response)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

错误:参数不是函数,未定义

来自分类Dev

PHP错误:调用未定义函数

来自分类Dev

调用未定义的函数__()错误-phpMyAdmin

来自分类Dev

错误:未定义不是函数

来自分类Dev

“'未定义'不是函数”错误

来自分类Dev

匿名函数错误:未定义$

来自分类Dev

收到“未定义不是函数”错误

来自分类Dev

未定义的函数错误引用

来自分类Dev

forEach()匿名函数未定义错误

来自分类Dev

定义函数的未定义错误

来自分类Dev

递归函数上的Python AST exec“ ...未定义”错误

来自分类Dev

Codeigniter函数未定义的错误

来自分类Dev

javascript获取函数未定义错误

来自分类Dev

未定义不是函数javascript错误

来自分类Dev

错误:未定义不是函数

来自分类Dev

未定义的php函数错误

来自分类Dev

未定义Javascript错误不是函数

来自分类Dev

引用错误:函数未定义

来自分类Dev

收到“未定义不是函数”错误

来自分类Dev

Angular JS函数未定义错误

来自分类Dev

jQuery-函数未定义错误

来自分类Dev

Javascript编程,函数未定义错误

来自分类Dev

使用函数的未定义变量错误

来自分类Dev

致命错误:调用未定义的函数

来自分类Dev

phpMyAdmin错误调用未定义的函数

来自分类Dev

Python 函数未定义

来自分类Dev

R中的错误未定义函数“:=”

来自分类Dev

React 中的函数未定义错误

来自分类Dev

错误:构造函数未定义