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

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

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

本文實(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()

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

相關(guān)文章

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

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

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

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

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

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

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

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

    數(shù)據(jù)類型是編程語(yǔ)言最重要的特征,它區(qū)分了我們可以存儲(chǔ)的不同類型的數(shù)據(jù),如字符串、int和float,這篇文章主要介紹了兩種不同的方法來(lái)檢查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ù)化,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • python Celery定時(shí)任務(wù)的示例

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

    這篇文章主要介紹了python Celery定時(shí)任務(wù)的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    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的用法,本文通過(guò)示例代碼介紹的非常詳細(xì),文中補(bǔ)充介紹了torch.nn.dropout和torch.nn.dropout2d的區(qū)別,需要的朋友可以參考下
    2023-04-04
  • pycharm訪問(wèn)mysql數(shù)據(jù)庫(kù)的方法步驟

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

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

    在pycharm中顯示python畫(huà)的圖方法

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

最新評(píng)論

天气| 织金县| 铜鼓县| 涞水县| 祥云县| 武冈市| 和平区| 敦煌市| 抚顺县| 白河县| 隆德县| 湘阴县| 措美县| 阳谷县| 郁南县| 轮台县| 云南省| 日喀则市| 德庆县| 广汉市| 武胜县| 南投市| 太白县| 项城市| 巴林左旗| 孟村| 镇康县| 长兴县| 泸溪县| 三门峡市| 灵川县| 潜山县| 庄浪县| 鱼台县| 禹州市| 寿阳县| 龙泉市| 宁河县| 辽宁省| 中方县| 论坛|