(在lua中通过loadfile, setfenv实现)
python当然也可以:
cat config.py
bar = 10
foo=100
cat python_as_config.py:
ns = {}
execfile('config.py', ns)
print "\n".join(sorted(dir(ns)))
print "*"*80
print ns['foo']
print ns['bar']
缺点是不像lua那么可以以成员的方式访问table中的变量,如ns.foo, ns.bar...
例子: https://github.com/baiyanhuang/blog/tree/master/arena/python/python_as_config
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8