Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize a simple data Management system based on Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to achieve a simple data management system based on Python. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

In order to conveniently record data and modify data, there is no energy to do a complete system to manage data. Therefore, a simple data management system is directly implemented in the console of python, including the addition, deletion, modification and query of data, and so on. You only need to call the corresponding functions at the console level to call the query, modification and other functions, and record the implementation process here.

Create an mysql data table

Use the familiar database client to operate, and here the navicate client is used to create the corresponding data table.

Create a database and specify an encoded character set.

CREATE DATABASE `data_ boc` CHARACTER SET 'utf8mb4' COLLATE' utf8mb4_general_ci'

Create data record table boc

CREATE TABLE `boc` (`boc`) bigint (`boc`) NOT NULL COMMENT 'data record number ID_ as the primary key', `boc_ address` varchar (255th) 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) add, delete, modify, check import pymysql as mysql # import mysql drive from pprint import pprint # import beautiful data print library

Determine what functions need to be implemented, print out a list of features in the console, and enter the use of the background system by entering the tag in front of each function list in the console.

Def current_menu ():''function list display: return:' 'pprint ('-simple data management system -') pprint ('system function implementation:') pprint ('1-query data list') pprint ('2-New Add data list') pprint ('exit- exit system') pprint ('more features, Not implemented yet')

Write a database connection creation function that is called directly when modifying or querying data.

Def cteate_connection ():''create a database connection: return:' 'connection = mysql.connect (host='127.0.0.1', user='root', password='root', database='data_boc') return connection

Write a function to save data for the implementation of the new function of the data list.

Def set_data ():''add data save: return:' 'pprint (currently enter [2-add data list]) id = input (' enter data number') id = int (id) boc_address = str (input ('enter detailed address') boc_code = str (input ('enter specific code')) boc_email = str (input ('enter the correct mailbox') boc_name = str (input ('enter the data name')) pprint ('data entry completed Start saving.') 'create a database connection' 'connection = cteate_connection () cursor = connection.cursor () insert_sql = "insert into boc (id_,boc_address,boc_code,boc_email,boc_name) values ('% danjinpaijie% sfujingheng% sfujingheng% smaginomo% s)"% (id, boc_address,boc_code,boc_email) Boc_name) try: cursor.execute (insert_sql) connection.commit () except: connection.rollback () print ("data save exception...") Connection.close () pprint ('data saved...')

Write the query function of the data list.

Def get_data (): pprint ('currently enter [1-query data list]')''create a database connection' '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 ({'data number': id 'detailed address': boc_address,' specific code': boc_code,' email address': boc_email,' name': boc_name}) pprint ('data result: {}' .format (res_list)) connection.commit () except: print ("data query exception.") Connection.close () pprint ('data query completed.') Launch the application if _ _ name__ = ='_ main__': while True: current_menu () chiose_code = input ('input menu number:') if str (chiose_code) = = '2commands: set_data () if str (chiose_code) = =' 1subscription: get_data () if str (chiose_code) = =' Exit': break above is how to implement a simple data management system based on Python. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report