现在的位置: 首页 > 综合 > 正文

写了一个基于文本菜单的模块, 自己取名: menu_util.py

2013年02月26日 ⁄ 综合 ⁄ 共 4326字 ⁄ 字号 评论关闭

原来以为python会自带这么一相模块,毕竟这是一个很普遍的需求,但查了一些有关python库的reference没有发现有这么个现成的库,在csdn的python版发帖询问了一下:http://topic.csdn.net/u/20101227/15/22408509-7d0d-4660-8d2c-b97822761abc.html?54614,同样没有结果.

 

工作还得继续,于是乎自己动手,丰衣足食. 代码如下:

 

下面是使用这模块的三个示例文件:

main_menu.py

 

sub_a.py:

 

sub_sub_b.py:

 

 

运行main_menu.py的结果如下:

[root@louis menu]# ./main_menu.py
root:
        1) 1st_a
        2) 1st_b

Select option number ( b>ack or l>ist ) (b): 1
root -> 1st_a:
        1) 2nd_a
        2) 2nd_b

Select option number ( b>ack or l>ist ) (b): 1
root -> 1st_a -> 2nd_a:
        1) 3rd_a
        2) 3rd_b

Select option number ( b>ack or l>ist ) (b): 1
in sub_sub_sub_a()

Select option number ( b>ack or l>ist ) (b): l

root -> 1st_a -> 2nd_a:
        1) 3rd_a
        2) 3rd_b

Select option number ( b>ack or l>ist ) (b): 2
in sub_sub_sub_b()

Select option number ( b>ack or l>ist ) (b): l

root -> 1st_a -> 2nd_a:
        1) 3rd_a
        2) 3rd_b

Select option number ( b>ack or l>ist ) (b): b
root -> 1st_a:
        1) 2nd_a
        2) 2nd_b

Select option number ( b>ack or l>ist ) (b): 2
in sub_sub_b.main()
root -> 1st_a:
        1) 2nd_a
        2) 2nd_b

Select option number ( b>ack or l>ist ) (b): b
root:
        1) 1st_a
        2) 1st_b

Select option number ( b>ack or l>ist ) (b): 2
print in func_b()

Select option number ( b>ack or l>ist ) (b):

抱歉!评论已关闭.