• <bdo id='pS7nv'></bdo><ul id='pS7nv'></ul>
    <tfoot id='pS7nv'></tfoot>
    1. <i id='pS7nv'><tr id='pS7nv'><dt id='pS7nv'><q id='pS7nv'><span id='pS7nv'><b id='pS7nv'><form id='pS7nv'><ins id='pS7nv'></ins><ul id='pS7nv'></ul><sub id='pS7nv'></sub></form><legend id='pS7nv'></legend><bdo id='pS7nv'><pre id='pS7nv'><center id='pS7nv'></center></pre></bdo></b><th id='pS7nv'></th></span></q></dt></tr></i><div id='pS7nv'><tfoot id='pS7nv'></tfoot><dl id='pS7nv'><fieldset id='pS7nv'></fieldset></dl></div>

        <small id='pS7nv'></small><noframes id='pS7nv'>

      1. <legend id='pS7nv'><style id='pS7nv'><dir id='pS7nv'><q id='pS7nv'></q></dir></style></legend>

        如何访问环境变量值

        How to access environment variable values(如何访问环境变量值)

      2. <legend id='OJd94'><style id='OJd94'><dir id='OJd94'><q id='OJd94'></q></dir></style></legend>

        <small id='OJd94'></small><noframes id='OJd94'>

            <bdo id='OJd94'></bdo><ul id='OJd94'></ul>
                <i id='OJd94'><tr id='OJd94'><dt id='OJd94'><q id='OJd94'><span id='OJd94'><b id='OJd94'><form id='OJd94'><ins id='OJd94'></ins><ul id='OJd94'></ul><sub id='OJd94'></sub></form><legend id='OJd94'></legend><bdo id='OJd94'><pre id='OJd94'><center id='OJd94'></center></pre></bdo></b><th id='OJd94'></th></span></q></dt></tr></i><div id='OJd94'><tfoot id='OJd94'></tfoot><dl id='OJd94'><fieldset id='OJd94'></fieldset></dl></div>
                  <tbody id='OJd94'></tbody>
                <tfoot id='OJd94'></tfoot>
                1. 本文介绍了如何访问环境变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我设置了一个我想在我的 Python 应用程序中访问的环境变量.我如何获得它的价值?

                  I set an environment variable that I want to access in my Python application. How do I get its value?

                  推荐答案

                  通过os.environ

                  import os
                  print(os.environ['HOME'])
                  

                  或者您可以使用以下命令查看所有环境变量的列表:

                  Or you can see a list of all the environment variables using:

                  os.environ
                  

                  有时您可能需要查看完整列表!

                  As sometimes you might need to see a complete list!

                  # using get will return `None` if a key is not present rather than raise a `KeyError`
                  print(os.environ.get('KEY_THAT_MIGHT_EXIST'))
                  
                  # os.getenv is equivalent, and can also give a default value instead of `None`
                  print(os.getenv('KEY_THAT_MIGHT_EXIST', default_value))
                  

                  Windows 上的 Python 默认安装 位置是 C:Python.如果您想在运行 python 时找出答案,可以这样做:

                  The Python default installation location on Windows is C:Python. If you want to find out while running python you can do:

                  import sys
                  print(sys.prefix)
                  

                  这篇关于如何访问环境变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                  <legend id='6SZrx'><style id='6SZrx'><dir id='6SZrx'><q id='6SZrx'></q></dir></style></legend>

                      <tbody id='6SZrx'></tbody>

                      1. <tfoot id='6SZrx'></tfoot>

                        <small id='6SZrx'></small><noframes id='6SZrx'>

                        • <bdo id='6SZrx'></bdo><ul id='6SZrx'></ul>

                          <i id='6SZrx'><tr id='6SZrx'><dt id='6SZrx'><q id='6SZrx'><span id='6SZrx'><b id='6SZrx'><form id='6SZrx'><ins id='6SZrx'></ins><ul id='6SZrx'></ul><sub id='6SZrx'></sub></form><legend id='6SZrx'></legend><bdo id='6SZrx'><pre id='6SZrx'><center id='6SZrx'></center></pre></bdo></b><th id='6SZrx'></th></span></q></dt></tr></i><div id='6SZrx'><tfoot id='6SZrx'></tfoot><dl id='6SZrx'><fieldset id='6SZrx'></fieldset></dl></div>