Home >Backend Development >Python Tutorial >用python代码做configure文件

用python代码做configure文件

WBOY
WBOYOriginal
2016-06-16 08:43:041547browse

(在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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn