Python编程系列---使用字典实现路由静态路由
生活随笔
收集整理的這篇文章主要介紹了
Python编程系列---使用字典实现路由静态路由
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 # 實現一個路由表,將url和功能函數的對應關系存到這個字典中
20 router_dict = {'index.html':index,'bbs.html':bbs}
21
22 def run(url):
23 # 通過傳入訪問地址,獲取對應的功能函數
24 func = router_dict[url]
25
26 func()
27
28
29 run('index.html')
30
31 run('bbs.html')
?
如果你和我有共同愛好,我們可以加個好友一起交流哈!
?
轉載于:https://www.cnblogs.com/ywk-1994/p/9543306.html
總結
以上是生活随笔為你收集整理的Python编程系列---使用字典实现路由静态路由的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台式电脑主板测试/升级BIOS
- 下一篇: [转]布隆过滤器详解