|
Recently wrote a program process of variables encountered a Python variable is the value of a variable, or variable, and then I want to take the final value, thanks to the great google, wrote this article under record. First on the code:
#! / Usr / bin / env python
# Encoding = utf-8
import inspect
import ConfigParser
confPath = "/ home / linuxidc / config / config"
def modify_config (domain_name, app_type, port, if_api, vip, svn, svnver, yfb_ip, cron_ip, hosts, hostname, if_cas_oa, if_session, if_nginx, check_apps_dir, health_check):
if vip is None:
vip = ""
if yfb_ip is None:
yfb_ip = ""
if cron_ip is None:
cron_ip = ""
if hosts is None:
hosts = ""
if if_cas_oa is None:
if_cas_oa = ""
if if_session is None:
if_session = ""
# Updates the specified section, the value of the option
conf = ConfigParser.ConfigParser ()
conf.read (confPath)
### Inspect.getargspec this role is to take the function's parameter list
arg_list = inspect.getargspec (modify_config) .args
### Following the second argument conf.set I just want to take arg value, and the third would like to take arg parameter value of a variable value, because the value of arg is itself a function of the parameters modify_config
for arg in arg_list:
conf.set ( "online", arg, locals (). get (arg))
conf.write (open (confPath, "w"))
if __name__ == '__main__':
domain_name = "www.linuxidc.com"
app_type = "osp"
port = "8081"
if_api = "1"
vip = "192.168.0.1"
svn = "https://svn.tools.linuxidc.com/svn/"
svnver = "24562"
yfb_ip = "192.168.0.1"
cron_ip = "192.168.0.2"
hosts = "www.linuxidc.com"
hostname = "JD-linuxidc-COM"
if_cas_oa = "0"
if_session = "mcs2"
if_nginx = "1"
check_apps_dir = "0"
health_check = "_health_check"
modify_config (domain_name, app_type, port, if_api, vip, svn, svnver, yfb_ip, cron_ip, hosts, hostname, if_cas_oa, if_session, if_nginx, check_apps_dir, health_check) |
|
|
|