Make a configure file in python code
- 2020-04-02 13:53:17
- OfStack
(implemented by loadfile, setfenv in lua)
Python can also:
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']
The disadvantage is that unlike lua, you can access variables in the table as members, such as ns.foo, ns.bar...
Example: (link: https://github.com/baiyanhuang/blog/tree/master/arena/python/python_as_config)