python数据库编程 ODBC方式实现通讯录


Posted in Python onMarch 27, 2020

Python 数据库编程,ODBC方式实现通讯录,供大家参考,具体内容如下

#-*-coding:utf-8-*-
import pyodbc
import os
def SelectInfo(hcon,hcur):
 hcur.execute('select * from PassMapT')
 ptitle=('ID','Item','Pwd','other')
 print(ptitle)
 result=hcur.fetchall()
 for item in result:
 print(item)
 print('')

def AddInfo(hcon,hcur):
 id=int(input('please input ID: '))
 item=str(input('please input Item: '))
 pwd=str(input('please input Tel 1: '))
 other=str(input('please input Other: '))
 sql="insert into PassMapT(id,item,pwd,other) values(?,?,?,?)"
 try:
 hcur.execute(sql,(id,item,pwd,other))
 hcon.commit()
 except:
 hcon.rollback()

def DeleteInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of delete: '))
 sql="delete from PassMapT where id=?"
 try:
 hcur.execute(sql,(did,))
 hcon.commit()
 except:
 hcon.rollback()

def UpdateInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of update: '))
 
 sqlitem="update PassMapT set item=? where id=?"
 item=str(input('please input Item: '))
 try:
 hcur.execute(sqlitem,(item,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlpwd="update PassMapT set pwd=? where id=?"
 pwd=str(input('please input Pwd: '))
 try:
 hcur.execute(sqlpwd,(pwd,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlother="update PassMapT set other=? where id=?"
 other=str(input('please input other: '))
 try:
 hcur.execute(sqlother,(other,did))
 hcon.commit()
 except:
 hcon.rollback()
 
def Meau():
 print('1.diaplay')
 print('2.add')
 print('3.update')
 print('4.delete')
 print('5.cls')
 print('0.exit')
 sel=9
 while(sel>5 or sel<0):
 sel=int(input('please choice: '))
 return sel

def main():
 hcon = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=127.0.0.1;DATABASE=PasswordMap;UID=sa;PWD=lptpwd')
 hcur=hcon.cursor()
 
 while(True):
 sel=Meau()
 if(sel==1):
 SelectInfo(hcon,hcur)
 elif(sel==2):
 AddInfo(hcon,hcur)
 elif(sel==3):
 UpdateInfo(hcon,hcur)
 elif(sel==4):
 DeleteInfo(hcon,hcur)
 elif(sel==5):
 os.system('cls')
 else:
 break
 hcur.close()
 hcon.close()

if __name__=='__main__':
 main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中解析JSON并同时进行自定义编码处理实例
Feb 08 Python
Python编写生成验证码的脚本的教程
May 04 Python
Python3.X 线程中信号量的使用方法示例
Jul 24 Python
Python入门之三角函数tan()函数实例详解
Nov 08 Python
pandas 选择某几列的方法
Jul 03 Python
python+openCV利用摄像头实现人员活动检测
Jun 22 Python
Python将视频或者动态图gif逐帧保存为图片的方法
Sep 10 Python
Pandas实现dataframe和np.array的相互转换
Nov 30 Python
python实现单目标、多目标、多尺度、自定义特征的KCF跟踪算法(实例代码)
Jan 08 Python
Pytorch模型转onnx模型实例
Jan 15 Python
python工具快速为音视频自动生成字幕(使用说明)
Jan 27 Python
Python turtle编写简单的球类小游戏
Mar 31 Python
django 读取图片到页面实例
Mar 27 #Python
django ListView的使用 ListView中获取url中的参数值方式
Mar 27 #Python
django列表筛选功能的实现代码
Mar 27 #Python
python实现猜数游戏
Mar 27 #Python
手把手教你安装Windows版本的Tensorflow
Mar 26 #Python
python pandas.DataFrame.loc函数使用详解
Mar 26 #Python
Python计算指定日期是今年的第几天(三种方法)
Mar 26 #Python
You might like
PHP读取目录下所有文件的代码
2008/01/07 PHP
初步介绍PHP扩展开发经验分享
2012/09/06 PHP
ThinkPHP3.1新特性之Action参数绑定
2014/06/19 PHP
ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法
2014/10/29 PHP
PHP判断浏览器、判断语言代码分享
2015/03/05 PHP
PHP大文件切割上传功能实例分析
2019/07/01 PHP
JavaScript与Div对层定位和移动获得坐标的实现代码
2010/09/08 Javascript
jQuery中使用了document和window哪些属性和方法小结
2011/09/13 Javascript
javascript随机将第一个dom中的图片添加到第二个div中示例
2013/10/08 Javascript
JavaScript splice()方法详解
2020/09/22 Javascript
用js+iframe形成页面的一种遮罩效果的具体实现
2013/12/31 Javascript
页面加载完成后再执行JS的jquery写法以及区别说明
2014/02/22 Javascript
深入理解Javascript中的自执行匿名函数
2016/06/03 Javascript
webpack+vue.js实现组件化详解
2016/10/12 Javascript
JavaScript实现JSON合并操作示例【递归深度合并】
2018/09/07 Javascript
JS函数内部属性之arguments和this实例解析
2018/10/07 Javascript
Three.JS实现三维场景
2018/12/30 Javascript
vue 实现Web端的定位功能 获取经纬度
2019/08/08 Javascript
vue实现图书管理系统
2020/12/29 Vue.js
Python交换变量
2008/09/06 Python
寻找网站后台地址的python脚本
2014/09/01 Python
Python脚本在Appium库上对移动应用实现自动化测试
2015/04/17 Python
Python实战小程序利用matplotlib模块画图代码分享
2017/12/09 Python
python:删除离群值操作(每一行为一类数据)
2020/06/08 Python
html5应用缓存_动力节点Java学院整理
2017/07/13 HTML / CSS
HTML5 Canvas+JS控制电脑或手机上的摄像头实例
2014/05/03 HTML / CSS
Peter Millar官网:美国高档生活服饰品牌
2018/07/02 全球购物
总经理驾驶员岗位职责
2013/12/04 职场文书
采购部经理岗位职责
2014/02/10 职场文书
优秀毕业生事迹材料
2014/02/12 职场文书
不打扫卫生检讨书
2014/02/12 职场文书
金融保险专业求职信
2014/09/03 职场文书
小学毕业典礼演讲稿
2014/09/09 职场文书
化验室岗位职责
2015/02/14 职场文书
辞职信范文大全
2015/03/02 职场文书
如何搭建 MySQL 高可用高性能集群
2021/06/21 MySQL