亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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關(guān)于sys.argv[]的用法及說明

    Python關(guān)于sys.argv[]的用法及說明

    sys.argv[]是Python中用于從程序外部獲取參數(shù)的列表,參數(shù)索引從0開始,0索引代表腳本名稱本身,后續(xù)索引代表傳遞給腳本的參數(shù),通過指定索引可以獲取特定的參數(shù),如sys.argv[1]獲取第一個傳入?yún)?shù),當(dāng)傳入多個參數(shù)時,可以通過切片或循環(huán)獲取全部參數(shù)
    2024-09-09
  • 使用Python?Turtle庫帶你玩轉(zhuǎn)創(chuàng)意繪圖(畫個心,寫個花)

    使用Python?Turtle庫帶你玩轉(zhuǎn)創(chuàng)意繪圖(畫個心,寫個花)

    Python的turtle庫提供了一種有趣且易于上手的編程繪圖方式,適合初學(xué)者學(xué)習(xí),通過本文的介紹,你將了解到如何進行畫布設(shè)置、畫筆屬性的調(diào)整、畫筆的移動與控制,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-11-11
  • pytorch 常用線性函數(shù)詳解

    pytorch 常用線性函數(shù)詳解

    今天小編就為大家分享一篇pytorch 常用線性函數(shù)詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • python驗證碼識別教程之利用滴水算法分割圖片

    python驗證碼識別教程之利用滴水算法分割圖片

    這篇文章主要給大家介紹了關(guān)于python驗證碼識別教程之利用滴水算法分割圖片的相關(guān)資料,文章中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • python3將變量寫入SQL語句的實現(xiàn)方式

    python3將變量寫入SQL語句的實現(xiàn)方式

    這篇文章主要介紹了python3將變量寫入SQL語句的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • python實現(xiàn)數(shù)據(jù)結(jié)構(gòu)中雙向循環(huán)鏈表操作的示例

    python實現(xiàn)數(shù)據(jù)結(jié)構(gòu)中雙向循環(huán)鏈表操作的示例

    這篇文章主要介紹了python實現(xiàn)數(shù)據(jù)結(jié)構(gòu)中雙向循環(huán)鏈表操作的示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Python基于pillow庫實現(xiàn)生成圖片水印

    Python基于pillow庫實現(xiàn)生成圖片水印

    這篇文章主要介紹了Python基于pillow庫實現(xiàn)生成圖片水印,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • Python中l(wèi)ist初始化方法示例

    Python中l(wèi)ist初始化方法示例

    這篇文章主要介紹了Python中l(wèi)ist初始化方法,分析了list初始化常用的方法與相關(guān)使用注意事項,需要的朋友可以參考下
    2016-09-09
  • 用Pytorch訓(xùn)練CNN(數(shù)據(jù)集MNIST,使用GPU的方法)

    用Pytorch訓(xùn)練CNN(數(shù)據(jù)集MNIST,使用GPU的方法)

    今天小編就為大家分享一篇用Pytorch訓(xùn)練CNN(數(shù)據(jù)集MNIST,使用GPU的方法),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Python標(biāo)準(zhǔn)庫中的logging用法示例詳解

    Python標(biāo)準(zhǔn)庫中的logging用法示例詳解

    logging是Python標(biāo)準(zhǔn)庫中記錄常用的記錄日志庫,通過logging模塊存儲各種格式的日志,主要用于輸出運行日志,可以設(shè)置輸出日志的等級、日志保存路徑、日志文件回滾等,這篇文章主要介紹了Python標(biāo)準(zhǔn)庫中的logging,需要的朋友可以參考下
    2022-09-09

最新評論