最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python數(shù)據(jù)庫編程 Mysql實(shí)現(xiàn)通訊錄

 更新時間:2020年03月27日 09:22:47   作者:Ugex  
這篇文章主要為大家詳細(xì)介紹了python數(shù)據(jù)庫編程,Mysql實(shí)現(xiàn)通訊錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Mysql實(shí)現(xiàn)通訊錄的具體代碼,供大家參考,具體內(nèi)容如下

#-*-code:utf-8-*-
import pymysql
def CreateTable():
 hcon=pymysql.connect(host='localhost',user='root',password='lptpwd',database='contract',charset='utf8')
 hcur=hcon.cursor()
 hcur.execute('drop table if exists contractlist')
 ctable='''
 create table contractlist
 (
 ID int(10) primary key,
 NAME varchar(20) not null,
 TELF char(11) not null,
 TELS char(11),
 OTHER varchar(50)
 )engine=myisam charset=utf8;
 '''
 hcur.execute(ctable)
 hcur.close()
 hcon.close()
 
def AddInfo(hcon,hcur):
 id=int(input('please input ID: '))
 name=str(input('please input Name: '))
 telf=str(input('please input Tel 1: '))
 tels=str(input('please input Tel 2: '))
 other=str(input('please input other: '))
 sql="insert into contractlist(id,name,telf,tels,other) values(%s,%s,%s,%s,%s)"
 try:
 hcur.execute(sql,(id,name,telf,tels,other))
 hcon.commit()
 except:
 hcon.rollback()
 
def DeleteInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of delete: '))
 sql="delete from contractlist where id=%s"
 try:
 hcur.execute(sql,(did,))
 hcon.commit()
 except:
 hcon.rollback()

def UpdateInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of update: '))
 
 sqlname="update contractlist set name=%s where id=%s"
 name=str(input('please input Name: '))
 try:
 hcur.execute(sqlname,(name,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqltelf="update contractlist set telf=%s where id=%s"
 telf=str(input('please input Tel 1: '))
 try:
 hcur.execute(sqltelf,(telf,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqltels="update contractlist set tels=%s where id=%s"
 tels=str(input('please input Tel 2: '))
 try:
 hcur.execute(sqltels,(tels,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlothers="update contractlist set other=%s where id=%s"
 other=str(input('please input other: '))
 try:
 hcur.execute(sqlothers,(other,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 
def SelectInfo(hcon,hcur):
 hcur.execute("select * from contractlist")
 result=hcur.fetchall()
 ptitle=('ID','Name','Tel 1','Tel 2','Other')
 print(ptitle)
 for findex in result:
 print(findex)
 
 print('')

 
def Meau():
 print('1.diaplay')
 print('2.add')
 print('3.update')
 print('4.delete')
 print('5.cls')
 print('0.exit')
 sel=9
 while(sel>5 or sel<0):
 sel=int(input('please choice: '))
 return sel
 
def main():
 #CreateTable()
 hcon=pymysql.connect(host='localhost',user='root',password='ltb12315',database='contract',charset='utf8')
 hcur=hcon.cursor()
 while(True):
 sel=Meau()
 if(sel==1):
 SelectInfo(hcon,hcur)
 elif(sel==2):
 AddInfo(hcon,hcur)
 elif(sel==3):
 UpdateInfo(hcon,hcur)
 elif(sel==4):
 DeleteInfo(hcon,hcur)
 elif(sel==5):
 os.system('cls')
 else:
 break
 print('-------------------------')
 hcur.close()
 hcon.close()
 
if __name__=="__main__":
 main()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • ipad上運(yùn)行python的方法步驟

    ipad上運(yùn)行python的方法步驟

    在本篇文章里小編給大家分享的是關(guān)于ipad上運(yùn)行python的方法步驟以及相關(guān)知識點(diǎn),有需要的朋友們學(xué)習(xí)下。
    2019-10-10
  • python實(shí)現(xiàn)簡單中文詞頻統(tǒng)計示例

    python實(shí)現(xiàn)簡單中文詞頻統(tǒng)計示例

    本篇文章主要介紹了python實(shí)現(xiàn)簡單中文詞頻統(tǒng)計示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • Qt實(shí)現(xiàn)炫酷啟動圖動態(tài)進(jìn)度條效果

    Qt實(shí)現(xiàn)炫酷啟動圖動態(tài)進(jìn)度條效果

    最近接到一個新需求,讓做一個動效進(jìn)度條。剛接手這個項(xiàng)目真的不知所措,后來慢慢理清思路,問題迎刃而解,下面小編通過本文給大家?guī)砹薗t實(shí)現(xiàn)炫酷啟動圖動態(tài)進(jìn)度條效果,感興趣的朋友一起看看吧
    2021-11-11
  • 檢查Python中的變量是否是字符串(兩種不同方法)

    檢查Python中的變量是否是字符串(兩種不同方法)

    數(shù)據(jù)類型是編程語言最重要的特征,它區(qū)分了我們可以存儲的不同類型的數(shù)據(jù),如字符串、int和float,這篇文章主要介紹了兩種不同的方法來檢查Python中的變量是否是字符串,需要的朋友可以參考下
    2023-08-08
  • Python基于paramunittest模塊實(shí)現(xiàn)excl參數(shù)化

    Python基于paramunittest模塊實(shí)現(xiàn)excl參數(shù)化

    這篇文章主要介紹了Python基于paramunittest模塊實(shí)現(xiàn)excl參數(shù)化,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04
  • python Celery定時任務(wù)的示例

    python Celery定時任務(wù)的示例

    這篇文章主要介紹了python Celery定時任務(wù)的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • pydantic-resolve嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars

    pydantic-resolve嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars

    這篇文章主要為大家介紹了pydantic-resolve解決嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars的使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>
    2023-04-04
  • Pytorch?nn.Dropout的用法示例詳解

    Pytorch?nn.Dropout的用法示例詳解

    這篇文章主要介紹了Pytorch?nn.Dropout的用法,本文通過示例代碼介紹的非常詳細(xì),文中補(bǔ)充介紹了torch.nn.dropout和torch.nn.dropout2d的區(qū)別,需要的朋友可以參考下
    2023-04-04
  • pycharm訪問mysql數(shù)據(jù)庫的方法步驟

    pycharm訪問mysql數(shù)據(jù)庫的方法步驟

    這篇文章主要介紹了pycharm訪問mysql數(shù)據(jù)庫的方法步驟。文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • 在pycharm中顯示python畫的圖方法

    在pycharm中顯示python畫的圖方法

    今天小編就為大家分享一篇在pycharm中顯示python畫的圖方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08

最新評論

广丰县| 天镇县| 南陵县| 于都县| 五莲县| 双城市| 健康| 和顺县| 板桥市| 阜康市| 武冈市| 内黄县| 铜山县| 社会| 台江县| 万年县| 哈密市| 夏河县| 诏安县| 迭部县| 健康| 蓝山县| 乌苏市| 桐柏县| 巴彦县| 马关县| 武乡县| 汝城县| 花垣县| 个旧市| 永修县| 怀集县| 康定县| 特克斯县| 清镇市| 嘉祥县| 曲水县| 屏东县| 宁武县| 济阳县| 鲁甸县|