python code to create configure file

高洛峰
Release: 2016-10-18 09:35:52
Original
1093 people have browsed it

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

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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!