Heim >Backend-Entwicklung >Python-Tutorial >用python代码做configure文件

用python代码做configure文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-16 08:43:041593Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn