版权声明:未经本人同意,禁止转载! https://blog.csdn.net/TianPingXian/article/details/81559406
#!/usr/bin/env python
# encoding: utf-8
'''
@author: morgan lions
@time: 8/10/18 9:57 AM
'''
from __future__ import print_function
def func_day(s):
print ('func_day:', s)
def func_year(s):
print ('func_year:', s)
def func_month(s):
print ('func_month:', s)
if __name__ == '__main__':
string = ['day', 'year', 'month']
for s in string:
func = globals().get('func_{0}'.format(s))
#参数可以传递各种类型,对象,包括函数
if s is 'day':
func('这里是Day函数')
if s is 'year':
func('这里是Year函数')
if s is 'month':
func('这里是Month函数')
还可以通过Python 内置函数 eval 来执行