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的装饰器模式与面向切面编程详解
Jun 21 Python
Python 正则表达式入门(中级篇)
Dec 07 Python
Python Numpy库安装与基本操作示例
Jan 08 Python
python经典趣味24点游戏程序设计
Jul 26 Python
python代码 FTP备份交换机配置脚本实例解析
Aug 01 Python
正则给header的冒号两边参数添加单引号(Python请求用)
Aug 09 Python
python rsa实现数据加密和解密、签名加密和验签功能
Sep 18 Python
使用PyQt的QLabel组件实现选定目标框功能的方法示例
May 19 Python
Scrapy 配置动态代理IP的实现
Sep 28 Python
Python Sqlalchemy如何实现select for update
Oct 12 Python
python 实现网易邮箱邮件阅读和删除的辅助小脚本
Mar 01 Python
Python操作CSV格式文件的方法大全
Jul 15 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生成动态验证码gif图片
2015/10/19 PHP
微信公众平台开发教程⑤ 微信扫码支付模式介绍
2019/04/10 PHP
PHP命名空间与自动加载机制的基础介绍
2019/08/25 PHP
jquery遍历input取得input的name
2009/04/27 Javascript
基于jQuery的左右滚动实现代码
2010/12/03 Javascript
js下获得客户端操作系统的函数代码(1:vista,2:windows7,3:2000,4:xp,5:2003,6:2008)
2011/10/31 Javascript
精心挑选的15款优秀jQuery 本特效插件和教程
2012/08/06 Javascript
Mac OS X 系统下安装和部署Egret引擎开发环境
2014/09/03 Javascript
AngularJS 视图详解及示例代码
2016/08/17 Javascript
微信小程序 教程之列表渲染
2016/10/18 Javascript
jquery uploadify隐藏上传进度的实现方法
2017/02/06 Javascript
为Jquery EasyUI 组件加上清除功能的方法(详解)
2017/04/13 jQuery
微信小程序页面开发注意事项整理
2017/05/18 Javascript
JS奇技之利用scroll来监听resize详解
2017/06/15 Javascript
vue中vee validate表单校验的几种基本使用
2018/06/25 Javascript
解决Vue2.0 watch对象属性变化监听不到的问题
2018/09/11 Javascript
[59:26]DOTA2上海特级锦标赛D组资格赛#1 EG VS VP第二局
2016/02/28 DOTA
python检测是文件还是目录的方法
2015/07/03 Python
TF-IDF与余弦相似性的应用(二) 找出相似文章
2017/12/21 Python
带你认识Django
2019/01/15 Python
python 阶乘累加和的实例
2019/02/01 Python
对python中的控制条件、循环和跳出详解
2019/06/24 Python
浅谈django2.0 ForeignKey参数的变化
2019/08/06 Python
vim自动补全插件YouCompleteMe(YCM)安装过程解析
2019/10/21 Python
selenium+python实现自动登陆QQ邮箱并发送邮件功能
2019/12/13 Python
使用Python+selenium实现第一个自动化测试脚本
2020/03/17 Python
Python3+PyCharm+Django+Django REST framework配置与简单开发教程
2021/02/16 Python
CSS3悬停效果案例应用
2012/11/21 HTML / CSS
国际领先的学术出版商:Springer
2017/01/11 全球购物
KEEN美国官网:美国人气户外休闲鞋品牌
2021/03/09 全球购物
施工资料员的岗位职责
2013/12/22 职场文书
幼儿园运动会口号
2014/06/07 职场文书
群众路线教育查摆剖析材料
2014/10/10 职场文书
文艺部部长竞选稿
2015/11/21 职场文书
使用Selenium实现微博爬虫(预登录、展开全文、翻页)
2021/04/13 Python
小程序实现侧滑删除功能
2022/06/25 Javascript