会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133534个问题
Python 全系列/第二十阶段:数据分析-数据管理/数据分析案例_案例2_电影数据分析 32386楼
Python 全系列/第十六阶段:Python 爬虫开发/scrapy框架使用(旧) 32387楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 32389楼
Python 全系列/第十七阶段:数据结构与算法/算法与数据结构(旧) 32391楼
WEB前端全系列/第三阶段:jQuery编程模块/jQuery基础知识(旧) 32392楼
JAVA 全系列/第八阶段:Linux入门到实战/Maven 32393楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Spring 32395楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于SpringSecurity实现后台登录功能 32397楼
人工智能/第五阶段:机器学习-线性回归/多元线性回归 32398楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 32399楼

import pymysql

class dbUtil():
    def __init__(self):
        self.connect = pymysql.connect(host='localhost', user='root', passwd='root', db='playmusic', charset='utf8')
        self.cursor = self.connect.cursor()


    def close(self):
        if self.cursor:
            self.close()
        if self.connect:
            self.close()

    def exeDML(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            count = self.connect.commit()
            return count
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.rollback()
        finally:
            self.close()

    def quryone(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            return self.cursor.fetchone()
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.close()
        finally:
            self.close()

    def quryall(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            return self.cursor.fetchall()
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.close()
        finally:
            self.close()

limage.png

老师以上代码会出现这个报错,我网上查了,说是超过最大递归深度,但是我写的另外一个一模一样的代码却可以正常运行,下面的这个代码是可以正常运行的。我检查了很多遍,实在找不出有什么区别

class dbUtil():
    def __init__(self):
        self.connect = pymysql.connect(host='localhost', user='root', passwd='root', db='playmusic', charset='utf8')
        self.cursor = self.connect.cursor()

    def close(self):
        if self.cursor:
            self.cursor.close()
        if self.connect:
            self.connect.close()

    def exeDML(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            count = self.connect.commit()
            return count
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.rollback()
        finally:
            self.close()

    def quryone(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            # self.cursor.fetchone()
            return self.cursor.fetchone()
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.close()
        finally:
            self.close()

    def quryall(self, sql, *args):
        try:
            self.cursor.execute(sql, args)
            return self.cursor.fetchall()
        except Exception as e:
            print(e)
            if self.connect:
                self.connect.close()
        finally:
            self.close()


Python 全系列/第六阶段:数据库与AI协同技术实战/项目-音乐播放器-旧 32400楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637