Python code makes a sample configure file

  • 2020-04-02 13:52:22
  • OfStack

In lua, lua is always used as a config file, or as a file to carry data - the benefit is that lua itself is easy to read, and then there is no need to write additional parsing code, as well as support for reading environment variables in configure files, conditional judgment, etc.

Lua via 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... www.jb51.net


Related articles: