課程
/后端開發
/Python
/Python辦公自動化
老師,你的案例文檔能不能上傳分享下
2020-06-02
源自:Python辦公自動化 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 ????#創建一個鏈接 ????def?connection(self): ????????#創建連接 ????????self.conn=pymysql.connect(host=self.host,port=self.port, ????????user=self.user,passwd=self.passwd, ????????db=self.db,charset=self.charset) ????????#創建游標 ????????self.cur=self.conn.cursor() ????#關閉鏈接 ????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
舉報
以實際工作場景出發,利用python高效快捷覆蓋全方位辦公自動化內容。
1 回答課程文檔內容
3 回答圖片傳入失敗
1 回答我這創建文件沒有問題,但是在加上的段落的時候報錯了
1 回答部分數據不能寫入
1 回答安裝不上python-docx
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2020-06-27
#mysqlhelper.py另存即可