解释执行.PYTHON环境变量

PYTHONHOME   

说明:嵌入PYTHONPATH或PYTHONSTARTUP

PYTHONPYTH   

说明:设置此全局环境变量,默认会被加入sys.path列表,方便导入模块儿

# -*- coding: utf-8 -*-
"""
#
# Authors: limanman
# OsChina: http://my.oschina.net/pydevops/
# Purpose:
#
"""
import os
import sys
import pprint


def main():
    """Main function."""
    # without PYTHONPATH
    cur_pypath_set = set(sys.path)
    pprint.pprint(cur_pypath_set)

    # with PYTHONPATH
    os.environ['PYTHONPATH'] = '/root/.supertab/'
    var_pypath = os.getenv('PYTHONPATH')
    if var_pypath:
        sys.path.append(var_pypath)
        res_pypath_set = set(sys.path)
        pprint.pprint(res_pypath_set)

    # get the difference set
    pprint.pprint(res_pypath_set-cur_pypath_set)

if __name__ == '__main__':
    main()

PYTHONSTARTUP

说明:交互模式启动时首先查找此全局变量然后执行此文件中变量制定的脚本

# -*- coding: utf-8 -*-
"""
#
# Authors: limanman
# OsChina: http://my.oschina.net/pydevops/
# Purpose:
#
"""
import os
import sys


def main():
    """Main function."""
    if PYTHONSTARTUP and os.path.exists(PYTHONSTARTUP):
        execfile(PYTHONSTARTUP)
    else:
        sys.exit('Found Error: handler PYTHONPATH(%s) with error, exit!' % (
            PYTHONSTARTUP))

if __name__ == '__main__':
    PYTHONSTARTUP = os.getenv('PYTHONSTARTUP')
    main()


你可能感兴趣的:(解释执行.PYTHON环境变量)