Python编程系列---使用字典实现路由静态路由
生活随笔
收集整理的這篇文章主要介紹了
Python编程系列---使用字典实现路由静态路由
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1 def index():
2 print('Index Page....')
3
4 def bbs():
5 print('BBS Page....')
6
7 def login():
8 print('Login Page....')
9
10 def center():
11 print('Center Page....')
12
13 def other():
14 print('訪問頁面不存在....')
15
16 def logout():
17 print('Logout Page...')
18
19 # 實(shí)現(xiàn)一個(gè)路由表,將url和功能函數(shù)的對(duì)應(yīng)關(guān)系存到這個(gè)字典中
20 router_dict = {'index.html':index,'bbs.html':bbs}
21
22 def run(url):
23 # 通過傳入訪問地址,獲取對(duì)應(yīng)的功能函數(shù)
24 func = router_dict[url]
25
26 func()
27
28
29 run('index.html')
30
31 run('bbs.html')
?
如果你和我有共同愛好,我們可以加個(gè)好友一起交流哈!
?
轉(zhuǎn)載于:https://www.cnblogs.com/ywk-1994/p/9543306.html
總結(jié)
以上是生活随笔為你收集整理的Python编程系列---使用字典实现路由静态路由的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台式电脑主板测试/升级BIOS
- 下一篇: [转]布隆过滤器详解