Skip to content

Commit e010665

Browse files
committed
更新循环测试
1 parent 6742746 commit e010665

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

test/test_loop.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
__author__ = 'zhanghe'
66

77
friend_dict = {
8+
# 'QQ号': '姓名',
89
'A_f': 'info_a',
910
'B_f': 'info_b',
1011
'C_f': 'info_c',
1112
'D_f': 'info_d'
1213
}
1314

1415
group_dict = {
16+
# '群号': '群名',
1517
'A_g': 'info_a',
1618
'B_g': 'info_b',
1719
'C_g': 'info_c',
@@ -20,26 +22,47 @@
2022

2123

2224
def show_list(dict_info):
23-
for i in dict_info:
24-
print i, dict_info[i]
25+
for key, value in dict_info.iteritems():
26+
print key, value
2527

26-
send_type = None
28+
29+
def get_msg():
30+
print '最新消息'
31+
32+
33+
msg_type = None
2734
while 1:
28-
print '\n-------------'
29-
print '1、发送好友消息'
30-
print '2、发送群组消息'
31-
print 'q、退出程序'
32-
command = raw_input("请输入类型: ")
33-
if command == '1':
34-
show_list(friend_dict) # 显示好友列表
35-
raw_input_msg = raw_input("输入好友消息: ")
36-
print raw_input_msg
37-
continue
38-
if command == '2':
39-
show_list(group_dict) # 显示群组列表
40-
raw_input_msg = raw_input("输入群组消息: ")
41-
print raw_input_msg
42-
continue
43-
if command == 'q':
35+
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
44+
if msg_type == '0': # 接收最新消息
45+
get_msg()
46+
continue
47+
if msg_type == '1':
48+
show_list(friend_dict) # 显示好友列表
49+
raw_input_msg = raw_input("输入好友消息: \n")
50+
if raw_input_msg == '#':
51+
msg_type = '#'
52+
else:
53+
print raw_input_msg
54+
continue
55+
if msg_type == '2':
56+
show_list(group_dict) # 显示群组列表
57+
raw_input_msg = raw_input("输入群组消息: \n")
58+
if raw_input_msg == '#':
59+
msg_type = '#'
60+
else:
61+
print raw_input_msg
62+
continue
63+
if msg_type == 'q':
64+
print '程序已退出'
65+
break
66+
except KeyboardInterrupt:
4467
print '程序已退出'
4568
break

0 commit comments

Comments
 (0)