課程
/后端開發(fā)
/Python
/Python辦公自動(dòng)化
老師,你的案例文檔能不能上傳分享下
2020-06-02
源自:Python辦公自動(dòng)化 3-9
正在回答
#mysqlhelper.py另存即可
import?pymysql class?dbhelper(): ????def?__init__(self,host,port,user,passwd,db,charset="utf8"): ????????self.host=host ????????self.port=port ????????self.user=user ????????self.passwd=passwd ????????self.db=db ????????self.charset=charset ????#創(chuàng)建一個(gè)鏈接 ????def?connection(self): ????????#創(chuàng)建連接 ????????self.conn=pymysql.connect(host=self.host,port=self.port, ????????user=self.user,passwd=self.passwd, ????????db=self.db,charset=self.charset) ????????#創(chuàng)建游標(biāo) ????????self.cur=self.conn.cursor() ????#關(guān)閉鏈接 ????def?closeconnection(self): ????????self.cur.close() ????????self.conn.close() ????#查詢一條語句 ????def?getonedata(self,sql): ????????try: ????????????self.connection() ????????????self.cur.execute(sql) ????????????result=self.cur.fetchone() ????????????self.closeconnection() ????????except?Exception: ????????????print(Exception) ????????return?result ????#添加/修改/刪除 ????def?executedata(self,sql): ????????try: ????????????self.connection() ????????????self.cur.execute(sql) ????????????self.conn.commit() ????????????self.closeconnection() ????????except?Exception: ????????????print(Exception) ????#批量插入 ????def?executemanydata(self,sql,vals): ????????try: ????????????self.connection() ????????????self.cur.executemany(sql,vals) ????????????self.conn.commit() ????????????self.closeconnection() ????????except?Exception: ????????????print(Exception)
慕慕8209279
舉報(bào)
以實(shí)際工作場(chǎng)景出發(fā),利用python高效快捷覆蓋全方位辦公自動(dòng)化內(nèi)容。
1 回答課程文檔內(nèi)容
3 回答圖片傳入失敗
1 回答我這創(chuàng)建文件沒有問題,但是在加上的段落的時(shí)候報(bào)錯(cuò)了
1 回答部分?jǐn)?shù)據(jù)不能寫入
1 回答安裝不上python-docx
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-06-27
#mysqlhelper.py另存即可