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

python操作數(shù)據(jù)庫之sqlite3打開數(shù)據(jù)庫、刪除、修改示例

 更新時(shí)間:2014年03月13日 11:20:30   作者:  
這篇文章主要介紹了python操作sqlite3打開數(shù)據(jù)庫、刪除、修改示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

#coding=utf-8
__auther__ = 'xianbao'
import sqlite3
# 打開數(shù)據(jù)庫
def opendata():
        conn = sqlite3.connect("mydb.db")
        cur = conn.execute("""create table if not exists tianjia(
id integer primary key autoincrement, username varchar(128), passworld varchar(128),
address varchar(125), telnum varchar(128))""")
        return cur, conn
#查詢?nèi)康男畔?/P>


def showalldata():
        print "-------------------處理后后的數(shù)據(jù)-------------------"
        hel = opendata()
        cur = hel[1].cursor()
        cur.execute("select * from tianjia")
        res = cur.fetchall()
        for line in res:
                for h in line:
                        print h,
                print
        cur.close()
#輸入信息


def into():
        username1 = str(raw_input("請(qǐng)輸入您的用戶名:"))
        passworld1 = str(raw_input("請(qǐng)輸入您的密碼:"))
        address1 = str(raw_input("請(qǐng)輸入您的地址:"))
        telnum1 = str(raw_input("請(qǐng)輸入您的聯(lián)系電話:"))
        return username1, passworld1, address1, telnum1
#  (添加)  往數(shù)據(jù)庫中添加內(nèi)容


def adddata():
        welcome = """-------------------歡迎使用添加數(shù)據(jù)功能---------------------"""
        print welcome
        person = into()
        hel = opendata()
        hel[1].execute("insert into tianjia(username, passworld, address, telnum)values (?,?,?,?)",
                                        (person[0], person[1], person[2], person[3]))
        hel[1].commit()
        print "-----------------恭喜你數(shù)據(jù),添加成功----------------"
        showalldata()
        hel[1].close()
#  (刪除)刪除數(shù)據(jù)庫中的內(nèi)容


def deldata():
        welcome = "------------------歡迎您使用刪除數(shù)據(jù)庫功能------------------"
        print welcome
        delchoice = raw_input("請(qǐng)輸入您想要?jiǎng)h除用戶的編號(hào):")
        hel = opendata()              # 返回游標(biāo)conn
        hel[1].execute("delete from tianjia where id ="+delchoice)
        hel[1].commit()
        print "-----------------恭喜你數(shù)據(jù),刪除成功----------------"
        showalldata()
        hel[1].close()
# (修改)修改數(shù)據(jù)的內(nèi)容


def alter():
        welcome = "--------------------歡迎你使用修改數(shù)據(jù)庫功能-----------------"
        print welcome
        changechoice = raw_input("請(qǐng)輸入你想要修改的用戶的編號(hào):")
        hel =opendata()
        person = into()
        hel[1].execute("update tianjia set username=?, passworld= ?,address=?,telnum=? where id="+changechoice,
                                (person[0], person[1], person[2], person[3]))
        hel[1].commit()
        showalldata()
        hel[1].close()
# 查詢數(shù)據(jù)


def searchdata():
        welcome = "--------------------歡迎你使用查詢數(shù)據(jù)庫功能-----------------"
        print welcome
        choice = str(raw_input("請(qǐng)輸入你要查詢的用戶的編號(hào):"))
        hel = opendata()
        cur = hel[1].cursor()
        cur.execute("select * from tianjia where id="+choice)
        hel[1].commit()
        row = cur.fetchone()
        id1 = str(row[0])
        username = str(row[1])
        passworld = str(row[2])
        address = str(row[3])
        telnum = str(row[4])
        print "-------------------恭喜你,你要查找的數(shù)據(jù)如下---------------------"
        print ("您查詢的數(shù)據(jù)編號(hào)是%s" % id1)
        print ("您查詢的數(shù)據(jù)名稱是%s" % username)
        print ("您查詢的數(shù)據(jù)密碼是%s" % passworld)
        print ("您查詢的數(shù)據(jù)地址是%s" % address)
        print ("您查詢的數(shù)據(jù)電話是%s" % telnum)
        cur.close()
        hel[1].close()
# 是否繼續(xù)


def contnue1(a):
        choice = raw_input("是否繼續(xù)?(y or n):")
        if choice == 'y':
                a = 1
        else:
                a = 0
        return a


if __name__ == "__main__":
        flag = 1
        while flag:
                welcome = "---------歡迎使用仙寶數(shù)據(jù)庫通訊錄---------"
                print welcome
                choiceshow = """
請(qǐng)選擇您的進(jìn)一步選擇:
(添加)往數(shù)據(jù)庫里面添加內(nèi)容
(刪除)刪除數(shù)據(jù)庫中內(nèi)容
(修改)修改書庫的內(nèi)容
(查詢)查詢數(shù)據(jù)的內(nèi)容
選擇您想要的進(jìn)行的操作:
"""
                choice = raw_input(choiceshow)
                if choice == "添加":
                        adddata()
                        contnue1(flag)
                elif choice == "刪除":
                        deldata()
                        contnue1(flag)
                elif choice == "修改":
                        alter()
                        contnue1(flag)
                elif choice == "查詢":
                        searchdata()
                        contnue1(flag)
                else:
                        print "你輸入錯(cuò)誤,請(qǐng)重新輸入"

相關(guān)文章

  • Python面向?qū)ο筮M(jìn)階學(xué)習(xí)

    Python面向?qū)ο筮M(jìn)階學(xué)習(xí)

    在本文里我們整理了關(guān)于Python面向?qū)ο蟮倪M(jìn)階學(xué)習(xí)知識(shí)點(diǎn)以及學(xué)習(xí)路線等內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-05-05
  • pytest配置文件pytest.ini的配置、原理與實(shí)際應(yīng)用詳解

    pytest配置文件pytest.ini的配置、原理與實(shí)際應(yīng)用詳解

    在Python的測(cè)試生態(tài)中,pytest無疑是最受歡迎的測(cè)試框架之一,在pytest的眾多配置文件中,pytest.ini無疑是最為重要和常用的一個(gè),本文將深入探討pytest.ini的配置、工作原理以及實(shí)際應(yīng)用場(chǎng)景,幫助讀者更好地理解和使用這一強(qiáng)大的工具,需要的朋友可以參考下
    2025-03-03
  • Python+wxPython實(shí)現(xiàn)批量文件擴(kuò)展名替換

    Python+wxPython實(shí)現(xiàn)批量文件擴(kuò)展名替換

    這篇文章主要介紹了如何使用 Python和wxPython創(chuàng)建一個(gè)簡(jiǎn)單的圖形界面應(yīng)用程序,使用戶能夠選擇文件夾、輸入要替換的文件類型和新的文件類型,并實(shí)現(xiàn)批量替換文件擴(kuò)展名的功能,有需要的可以參考一下
    2023-10-10
  • Pytorch中的model.train()?和?model.eval()?原理與用法解析

    Pytorch中的model.train()?和?model.eval()?原理與用法解析

    pytorch可以給我們提供兩種方式來切換訓(xùn)練和評(píng)估(推斷)的模式,分別是:model.train()?和?model.eval(),這篇文章主要介紹了Pytorch中的model.train()?和?model.eval()?原理與用法,需要的朋友可以參考下
    2023-04-04
  • python畫柱狀圖--不同顏色并顯示數(shù)值的方法

    python畫柱狀圖--不同顏色并顯示數(shù)值的方法

    今天小編就為大家分享一篇python畫柱狀圖--不同顏色并顯示數(shù)值的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • 跟老齊學(xué)Python之編寫類之四再論繼承

    跟老齊學(xué)Python之編寫類之四再論繼承

    本打算上篇文章就結(jié)束這個(gè)系列的,考慮了下,還是得加一章,算是對(duì)上一講的進(jìn)一步修改吧
    2014-10-10
  • OpenCV角點(diǎn)檢測(cè)的實(shí)現(xiàn)示例

    OpenCV角點(diǎn)檢測(cè)的實(shí)現(xiàn)示例

    角點(diǎn)通常被定義為兩條邊的交點(diǎn),本文主要介紹了OpenCV角點(diǎn)檢測(cè)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • python爬取梨視頻生活板塊最熱視頻

    python爬取梨視頻生活板塊最熱視頻

    這篇文章主要介紹了python爬取梨視頻生活板塊最熱視頻,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • python開發(fā)前景如何

    python開發(fā)前景如何

    在本篇文章中小編給大家整理了關(guān)于python開發(fā)前景的知識(shí)點(diǎn)及相關(guān)內(nèi)容,有興趣的朋友們可以跟著學(xué)習(xí)參考下。
    2020-06-06
  • python基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)

    python基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)

    這篇文章主要介紹了python基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)的方法,是非常實(shí)用技巧,需要的朋友可以參考下
    2014-09-09

最新評(píng)論

尚义县| 红桥区| 松滋市| 霍林郭勒市| 仁布县| 合阳县| 资阳市| 岳西县| 莒南县| 博爱县| 伊吾县| 东兰县| 凤山县| 鸡西市| 瓮安县| 昆山市| 泸水县| 永吉县| 天等县| 长治市| 济源市| 崇礼县| 荣成市| 武山县| 苍山县| 喜德县| 房山区| 犍为县| 赞皇县| 樟树市| 钦州市| 临海市| 兴山县| 丹棱县| 永昌县| 综艺| 滨海县| 花莲县| 仪陇县| 玛多县| 尉氏县|