Home  >  Article  >  Backend Development  >  python code to create configure file

python code to create configure file

高洛峰
高洛峰Original
2016-10-18 09:35:521132browse

In Lua, Lua is always used as a config file or a file carrying data - the advantage is that Lua itself is easy to read, and there is no need to write additional parsing code. It also supports reading environment variables, conditional judgments, etc. in the configure file.

Achieved in lua through 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']

The disadvantage is that unlike lua, you can access variables in the table as members, such as ns.foo, ns.bar...


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