Python code to make configure file example _python

Source: Internet
Author: User

In Lua, always using LUA as a config file, or a file that hosts data-the benefit is that LUA itself reads well and then does not require additional write-parsing code, but also supports reading environment variables, conditional judgments, etc. in configure files.

In Lua through LoadFile, setfenv implementation)

Python:

Cat config.py

bar =
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 a table in a member's way, such as Ns.foo, Ns.bar ... www.jb51.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.