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

用python代码做configure文件

WBOY
Release: 2016-06-16 08:43:04
Original
1570 people have browsed it

(在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']
Copy after login

缺点是不像lua那么可以以成员的方式访问table中的变量,如ns.foo, ns.bar...

例子: https://github.com/baiyanhuang/blog/tree/master/arena/python/python_as_config

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template