Skip to content

Commit 8a2a4d5

Browse files
committed
改善循环退出机制
1 parent e010665 commit 8a2a4d5

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

test/test_loop.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"""
55
__author__ = 'zhanghe'
66

7+
8+
import time
9+
10+
711
friend_dict = {
812
# 'QQ号': '姓名',
913
'A_f': 'info_a',
@@ -27,20 +31,13 @@ def show_list(dict_info):
2731

2832

2933
def get_msg():
30-
print '最新消息'
34+
print '最新消息[%s]' % time.ctime()
35+
time.sleep(2)
3136

3237

3338
msg_type = None
3439
while 1:
3540
try:
36-
if msg_type in ['?', '?', '', '#', None]: # ? 直接回车 回到菜单 初始进入 显示帮助
37-
print '\n-------------'
38-
print '0、接收最新消息'
39-
print '1、发送好友消息'
40-
print '2、发送群组消息'
41-
print 'q、退出程序'
42-
msg_type = raw_input('请选择类型: \n')
43-
continue
4441
if msg_type == '0': # 接收最新消息
4542
get_msg()
4643
continue
@@ -61,8 +58,23 @@ def get_msg():
6158
print raw_input_msg
6259
continue
6360
if msg_type == 'q':
64-
print '程序已退出'
65-
break
61+
print '确认退出(Y)'
62+
print '取消操作(N)'
63+
raw_input_msg = raw_input("程序即将退出: \n")
64+
if raw_input_msg in ['y', 'Y']:
65+
print '程序已退出'
66+
break
67+
else:
68+
msg_type = ''
69+
continue
70+
else: # ? 直接回车 回到菜单 初始进入 显示帮助
71+
print '\n-------------'
72+
print '0、接收最新消息'
73+
print '1、发送好友消息'
74+
print '2、发送群组消息'
75+
print 'q、退出程序'
76+
msg_type = raw_input('请选择类型: \n')
77+
continue
6678
except KeyboardInterrupt:
6779
print '程序已退出'
6880
break

0 commit comments

Comments
 (0)