php函数转为python函数
PHP中文网
PHP中文网 2017-04-10 16:42:44
0
1
406

函数如下:

function ChangeWord($keyword, $value, $changfun) {
    return is_callable($changfun) ? call_user_func($changfun, $keyword, $value) : $changfun;
}
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
迷茫
import types
import sys

def change_word(keyword, value, change_func):
    if callable(change_func):
        return change_func(keyword, value)
    else:
        return change_func

def test(keyword, value):
    print keyword
    print value

if __name__ == '__main__':
    change_word('hello', 'world', test)
    change_word('goodbye', 'world', lambda keyword,value: sys.stdout.write('%s, %s' % (keyword, value)))

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template