首页 > 编程语言 > 详细

Python 反射作用

时间:2016-04-08 14:53:32      阅读:233      评论:0      收藏:0      [点我收藏+]
反射 代码示例:
person.py
def run (a):
print ‘running %s‘%a
def eat():
print ‘eating‘
def talk():
print ‘taliking‘

player.py
import  person
def play(action):
return getattr(person,action)
action =play(‘run‘)
action(‘test‘)
action = play(‘eat‘)
action()
模块反射代码调用示例:
http_download.py
def download(a):
print ‘http download %s‘%a
def download2():
print ‘https download 2‘
https_download.py
def download(a):
print ‘http download %s‘%a
def download2():
print ‘https download 2‘

fanshe.py
import http_download
import https_download

def freeman_download(protocol):
download = __import__(protocol+"_download")
download.download(‘test‘)
#download.download2()

freeman_download(‘http‘)
freeman_download(‘https‘)



Python 反射作用

原文:http://www.cnblogs.com/yjz1/p/5365270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!