zoukankan      html  css  js  c++  java
  • python 获取系统环境变量 os.environ and os.putenv

    从一段code说起 “if "BATCH_CONFIG_INI" in os.environ:” 判断环境变量的值有没有定义

    如果定义的话就去环境变量的值,否则就取当前目录下的config.ini文件。

    1         if "BATCH_CONFIG_INI" in os.environ:
    2             print "Using custom ini file!"
    3             self.inifile = os.environ["BATCH_CONFIG_INI"]
    4         else:
    5             self.inifile = self.cur_file_dir() + "/config.ini"
    6         self.db_print ("inifile = (%s)" %(self.inifile))

    用Python Shell设置或获取环境变量的方法:

    一、设置系统环境变量

    1、os.environ['环境变量名称']='环境变量值' #其中key和value均为string类型

    2、os.putenv('环境变量名称', '环境变量值')

    二、获取系统环境变量

    1、os.environ['环境变量名称']

    2、os.getenv('环境变量名称')

  • 相关阅读:
    汉语-词语-转世:百科
    汉语-词语-往生:百科
    中缀表达式值
    车厢调度(train.cpp)
    字符串匹配问题
    计算(calc.cpp)
    2、括弧匹配检验
    2058 括号序列
    7909:统计数字
    1007. 计算余数
  • 原文地址:https://www.cnblogs.com/brownz/p/8360292.html
Copyright © 2011-2022 走看看