Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Charles~Liu
Python-100-Days
提交
eade73fd
P
Python-100-Days
项目概览
Charles~Liu
/
Python-100-Days
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Python-100-Days
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eade73fd
编写于
6月 28, 2018
作者:
骆昊的技术专栏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
'添加了PyMySQL的参考代码'
上级
0da68f50
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
163 addition
and
0 deletion
+163
-0
Day36-40/code/contact/main.py
Day36-40/code/contact/main.py
+155
-0
Day36-40/code/contact/test01.py
Day36-40/code/contact/test01.py
+8
-0
Day41-55/shop/static/images/Thumbs.db
Day41-55/shop/static/images/Thumbs.db
+0
-0
未找到文件。
Day36-40/code/contact/main.py
0 → 100644
浏览文件 @
eade73fd
import
pymysql
INSERT_CONTACTER
=
"""
insert into tb_contacter (conname, contel, conemail)
values (%s, %s, %s)
"""
DELETE_CONTACTER
=
"""
delete from tb_contacter where conid=%s
"""
UPDATE_CONTACTER
=
"""
update tb_contacter set conname=%s, contel=%s, conemail=%s
where conid=%s
"""
SELECT_CONTACTERS
=
"""
select conid as id, conname as name, contel as tel, conemail as email
from tb_contacter limit %s offset %s
"""
COUNT_CONTACTERS
=
"""
select count(conid) as total from tb_contacter
"""
def
input_contacter_info
():
name
=
input
(
'姓名: '
)
tel
=
input
(
'手机: '
)
email
=
input
(
'邮箱: '
)
return
name
,
tel
,
email
def
add_new_contacter
(
con
):
name
,
tel
,
email
=
input_contacter_info
()
try
:
with
con
.
cursor
()
as
cursor
:
if
cursor
.
execute
(
INSERT_CONTACTER
,
(
name
,
tel
,
email
))
==
1
:
print
(
'添加联系人成功!'
)
except
pymysql
.
MySQLError
as
err
:
print
(
err
)
print
(
'添加联系人失败!'
)
def
delete_contacter
(
con
,
contacter_id
):
try
:
with
con
.
cursor
()
as
cursor
:
if
cursor
.
execute
(
DELETE_CONTACTER
,
(
contacter_id
,
))
==
1
:
print
(
'联系人已经删除!'
)
except
pymysql
.
MySQLError
as
err
:
print
(
err
)
print
(
'删除联系人失败!'
)
def
edit_contacter_info
(
con
,
contacter
):
name
,
tel
,
email
=
input_contacter_info
()
contacter
[
'name'
]
=
name
or
contacter
[
'name'
]
contacter
[
'tel'
]
=
tel
or
contacter
[
'tel'
]
contacter
[
'email'
]
=
email
or
contacter
[
'email'
]
try
:
with
con
.
cursor
()
as
cursor
:
if
cursor
.
execute
(
UPDATE_CONTACTER
,
(
contacter
[
'name'
],
contacter
[
'tel'
],
contacter
[
'email'
],
contacter
[
'id'
]))
==
1
:
print
(
'联系人信息已经更新!'
)
except
pymysql
.
MySQLError
as
err
:
print
(
err
)
print
(
'更新联系人信息失败!'
)
def
show_contacter_detail
(
con
,
contacter
):
print
(
'姓名:'
,
contacter
[
'name'
])
print
(
'手机号:'
,
contacter
[
'tel'
])
print
(
'邮箱:'
,
contacter
[
'email'
])
choice
=
input
(
'是否编辑联系人信息?(yes|no)'
)
if
choice
==
'yes'
:
edit_contacter_info
(
con
,
contacter
)
else
:
choice
=
input
(
'是否删除联系人信息?(yes|no)'
)
if
choice
==
'yes'
:
delete_contacter
(
con
,
contacter
[
'id'
])
def
find_all_contacters
(
con
):
page
,
size
=
1
,
5
try
:
with
con
.
cursor
()
as
cursor
:
cursor
.
execute
(
COUNT_CONTACTERS
)
total
=
cursor
.
fetchone
()[
'total'
]
while
True
:
cursor
.
execute
(
SELECT_CONTACTERS
,
(
size
,
(
page
-
1
)
*
size
))
contacters_list
=
[]
for
index
,
row
in
enumerate
(
cursor
.
fetchall
()):
contacters_list
.
append
(
row
)
print
(
'[%d]: %s'
%
(
index
,
row
[
'name'
]))
choice
=
input
(
'是否查看联系人详情?(yes|no)'
)
if
choice
.
lower
()
==
'yes'
:
index
=
int
(
input
(
'请输入编号: '
))
if
0
<=
index
<
cursor
.
rowcount
:
show_contacter_detail
(
con
,
contacters_list
[
index
])
if
page
*
size
<
total
:
choice
=
input
(
'继续查看下一页?(yes|no)'
)
if
choice
.
lower
()
==
'yes'
:
page
+=
1
else
:
break
else
:
print
(
'没有下一页记录啦!'
)
break
except
pymysql
.
MySQLError
as
err
:
print
(
err
)
def
find_contacters_by_name
(
con
):
pass
def
find_contacters
(
con
):
while
True
:
print
(
'1. 查看所有联系人'
)
print
(
'2. 搜索联系人'
)
print
(
'3. 退出查找'
)
choice
=
int
(
input
(
'请输入: '
))
if
choice
==
1
:
find_all_contacters
(
con
)
elif
choice
==
2
:
find_contacters_by_name
(
con
)
elif
choice
==
3
:
break
def
main
():
con
=
pymysql
.
connect
(
host
=
'10.7.185.126'
,
port
=
3306
,
user
=
'root'
,
passwd
=
'123456'
,
db
=
'contact'
,
charset
=
'utf8'
,
autocommit
=
True
,
cursorclass
=
pymysql
.
cursors
.
DictCursor
)
while
True
:
print
(
'=====通讯录====='
)
print
(
'1. 新建联系人'
)
print
(
'2. 查找联系人'
)
print
(
'3. 退出系统'
)
print
(
'==============='
)
choice
=
int
(
input
(
'请选择: '
))
if
choice
==
1
:
add_new_contacter
(
con
)
elif
choice
==
2
:
find_contacters
(
con
)
elif
choice
==
3
:
con
.
close
()
print
(
'谢谢使用, 再见!'
)
break
if
__name__
==
'__main__'
:
main
()
Day36-40/code/contact/test01.py
0 → 100644
浏览文件 @
eade73fd
def
main
():
list1
=
[
'orange'
,
'grape'
,
'banana'
,
'waxberry'
,
'pitaya'
]
for
index
,
val
in
enumerate
(
list1
):
print
(
'%d: %s'
%
(
index
,
val
))
if
__name__
==
'__main__'
:
main
()
Day41-55/shop/static/images/Thumbs.db
已删除
100644 → 0
浏览文件 @
0da68f50
文件已删除
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录