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

基于Python實(shí)現(xiàn)一個(gè)簡易的數(shù)據(jù)管理系統(tǒng)

 更新時(shí)間:2021年12月25日 09:22:09   作者:Python集中營  
為了方便的實(shí)現(xiàn)記錄數(shù)據(jù)、修改數(shù)據(jù)沒有精力去做一個(gè)完整的系統(tǒng)去管理數(shù)據(jù)。因此,在python的控制臺直接實(shí)現(xiàn)一個(gè)簡易的數(shù)據(jù)管理系統(tǒng),包括數(shù)據(jù)的增刪改查等等。感興趣的可以跟隨小編一起學(xué)習(xí)一下

為了方便的實(shí)現(xiàn)記錄數(shù)據(jù)、修改數(shù)據(jù)沒有精力去做一個(gè)完整的系統(tǒng)去管理數(shù)據(jù)。因此,在python的控制臺直接實(shí)現(xiàn)一個(gè)簡易的數(shù)據(jù)管理系統(tǒng),包括數(shù)據(jù)的增刪改查等等。只需要在控制臺層面調(diào)用相應(yīng)的功能調(diào)用查詢、修改等功能,這里記錄一下實(shí)現(xiàn)過程。

創(chuàng)建mysql數(shù)據(jù)表

使用比較熟悉的數(shù)據(jù)庫客戶端來進(jìn)行操作,這里使用的是navicate客戶端來創(chuàng)建好相應(yīng)的數(shù)據(jù)表。

創(chuàng)建數(shù)據(jù)庫并指定編碼字符集。

CREATE DATABASE `data_boc` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';

創(chuàng)建數(shù)據(jù)記錄表boc

CREATE TABLE `boc`  (
  `id_` bigint(255) NOT NULL COMMENT '數(shù)據(jù)記錄編號,ID_作為主鍵',
  `boc_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `boc_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `boc_email` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `boc_name` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  PRIMARY KEY (`id_`) USING BTREE
)

增刪改查

import pymysql as mysql  # 導(dǎo)入mysql驅(qū)動器

from pprint import pprint  # 導(dǎo)入美觀的數(shù)據(jù)打印庫

確定一下需要實(shí)現(xiàn)哪些功能,在控制臺打印出功能列表,通過在控制臺輸入每個(gè)功能列表前面的標(biāo)記來進(jìn)入后臺系統(tǒng)的使用。

def current_menu():
    '''
    功能目錄列表展示
    :return:
    '''
    pprint('---------------- 簡易數(shù)據(jù)管理系統(tǒng) ----------------')
    pprint('系統(tǒng)功能實(shí)現(xiàn):<Python 集中營>')
    pprint('1- 查詢數(shù)據(jù)列表')
    pprint('2- 新增數(shù)據(jù)列表')
    pprint('exit- 退出系統(tǒng)')
    pprint('更多功能、暫未實(shí)現(xiàn)')

編寫數(shù)據(jù)庫連接的創(chuàng)建函數(shù),在修改或查詢數(shù)據(jù)時(shí)直接調(diào)用。

def cteate_connection():
    '''
    創(chuàng)建數(shù)據(jù)庫連接
    :return:
    '''
    connection = mysql.connect(host='127.0.0.1',
           user='root',
           password='root',
           database='data_boc')
    return connection

編寫保存數(shù)據(jù)的函數(shù)用于數(shù)據(jù)列表新增功能實(shí)現(xiàn)。

def set_data():
    '''
    新增數(shù)據(jù)保存
    :return:
    '''
    pprint('當(dāng)前進(jìn)入[2- 新增數(shù)據(jù)列表]')
    id = input('輸入數(shù)據(jù)編號')
    id = int(id)
    boc_address = str(input('輸入詳細(xì)地址'))
    boc_code = str(input('輸入具體編碼'))
    boc_email = str(input('輸入正確郵箱'))
    boc_name = str(input('輸入數(shù)據(jù)名稱'))
    pprint('數(shù)據(jù)輸入完成,開始保存...')
    '''創(chuàng)建數(shù)據(jù)庫接連'''
    connection = cteate_connection()
    cursor = connection.cursor()
    insert_sql = "insert into boc(id_,boc_address,boc_code,boc_email,boc_name) values('%d','%s','%s',%s,%s)" % (
    id, boc_address, boc_code, boc_email, boc_name)
    try:
        cursor.execute(insert_sql)
        connection.commit()
    except:
        connection.rollback()
        print("數(shù)據(jù)保存出現(xiàn)異常...")
    connection.close()
    pprint('數(shù)據(jù)保存完成...')

編寫數(shù)據(jù)列表的查詢功能函數(shù)。

def get_data():
    pprint('當(dāng)前進(jìn)入[1- 查詢數(shù)據(jù)列表]')
    '''創(chuàng)建數(shù)據(jù)庫連接'''
    connection = cteate_connection()
    cursor = connection.cursor()
    select_sql = "select * from boc"
    res_list = []
    try:
        cursor.execute(select_sql)
        res = cursor.fetchall()
        for row in res:
            id = row[0]
            boc_address = row[1]
            boc_code = row[2]
            boc_email = row[3]
            boc_name = row[4]
            res_list.append({'數(shù)據(jù)編號':id,'詳細(xì)地址':boc_address,'具體編碼':boc_code,'郵箱地址':boc_email,'名稱':boc_name})
        pprint('數(shù)據(jù)結(jié)果:{}'.format(res_list))
        connection.commit()
    except:
        print("數(shù)據(jù)查詢出現(xiàn)異常...")
    connection.close()
    pprint('數(shù)據(jù)查詢完成...')

啟動應(yīng)用?

if __name__ == '__main__':
    while True:
        current_menu()
        chiose_code = input('輸入菜單編號:')
        if str(chiose_code) == '2':
            set_data()
        if str(chiose_code) == '1':
            get_data()
        if str(chiose_code) == 'exit':
            break 

到此這篇關(guān)于基于Python實(shí)現(xiàn)一個(gè)簡易的數(shù)據(jù)管理系統(tǒng)的文章就介紹到這了,更多相關(guān)Python數(shù)據(jù)管理系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

锡林郭勒盟| 五莲县| 兴义市| 察隅县| 增城市| 莒南县| 海安县| 慈溪市| 东光县| 荣昌县| 南丰县| 沅江市| 五大连池市| 房产| 醴陵市| 清水县| 阿拉尔市| 曲水县| 霍山县| 堆龙德庆县| 乌鲁木齐市| 定西市| 本溪市| 仙游县| 汽车| 苏尼特左旗| 永宁县| 湖州市| 襄城县| 嘉鱼县| 南安市| 布拖县| 雷州市| 宝山区| 正宁县| 临沂市| 临清市| 南京市| 墨竹工卡县| 抚远县| 玛纳斯县|