首页 > 解决方案 > PEP8 清理 - 访问一个类的受保护成员 _last_executed

问题描述

我有下面的代码块,它捕获警告几种不同的查询类型并将它们写入很多,如果它们失败/警告,则向我发送谷歌聊天消息。我收到 pep8 错误str(cursor._last_executed)

访问类的受保护成员 _last_executed

我需要对此进行更改吗?它确实做我想做的事 - 将失败的 mysql 发送到日志

db = MySQLdb.connect("localhost", "root", "1234", "search")
cursor = db.cursor()
try:
    with warnings.catch_warnings(record=True) as w:
        if warn_type == 2:
            cursor.execute(query_string, kargs['field_split'] + kargs['user'])
        elif warn_type == 3:
            cursor.execute(query_string, (
                kargs['reportid'], kargs['timestamp'], kargs['reportid'], kargs['reportid'], kargs['timestamp']))
        else:
            cursor.execute(query_string, kargs['field_split'])
        db.commit()
        if w:
            logger.warning('Mysql Warning : %s', w[-1])
            logger.warning('Statement : %s', str(cursor._last_executed))
            logger.warning(kargs['field_split'])
            # noinspection PyUnresolvedReferences
            string_google = 'Warning - ' + str(w[-1].message) + ' - ' + str(cursor._last_executed)
            googlechat(string_google)

标签: pythonpep8

解决方案


推荐阅读