16.2反射實例

反射實例
r1模塊ide

__author__ = 'xiaojiaxin'
__file_name__ = 'r1'

def f1():
    return "首頁"
def f2():
    return "新聞"
def f3():
    return "關注"

r2模塊code

# -*-coding:utf-8 -*-
__author__ = 'xiaojiaxin'
__file_name__ = 'r2'

import r1
while True:
    shu=input("請輸入URL:")
    if hasattr(r1,shu):

        func=getattr(r1,shu)
        result=func()
        print(result)
    else:
        print("404")
相關文章
相關標籤/搜索