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

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

 更新時間: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("請輸入您的用戶名:"))
        passworld1 = str(raw_input("請輸入您的密碼:"))
        address1 = str(raw_input("請輸入您的地址:"))
        telnum1 = str(raw_input("請輸入您的聯(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("請輸入您想要刪除用戶的編號:")
        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("請輸入你想要修改的用戶的編號:")
        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("請輸入你要查詢的用戶的編號:"))
        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ù)編號是%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 = """
請選擇您的進一步選擇:
(添加)往數(shù)據(jù)庫里面添加內(nèi)容
(刪除)刪除數(shù)據(jù)庫中內(nèi)容
(修改)修改書庫的內(nèi)容
(查詢)查詢數(shù)據(jù)的內(nèi)容
選擇您想要的進行的操作:
"""
                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 "你輸入錯誤,請重新輸入"

相關(guān)文章

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

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

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

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

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

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

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

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

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

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

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

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

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

    OpenCV角點檢測的實現(xiàn)示例

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

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

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

    python開發(fā)前景如何

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

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

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

最新評論

徐闻县| 东明县| 萨嘎县| 赫章县| 山阴县| 辽阳市| 塘沽区| 穆棱市| 阿拉善右旗| 永新县| 张家川| 葵青区| 大竹县| 韶关市| 明光市| 抚顺市| 彰化县| 米易县| 沅江市| 垦利县| 杨浦区| 新乐市| 英山县| 右玉县| 绿春县| 沁阳市| 临沧市| 萍乡市| 青神县| 根河市| 当雄县| 中西区| 辽中县| 漳平市| 开阳县| 吕梁市| 通河县| 南康市| 连江县| 东兰县| 丹寨县|