• <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>

        如何访问环境变量值

        时间:2023-07-06

      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)
                  

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

                  上一篇:如何添加到 Windows 中的 PYTHONPATH,以便找到我的模块/包? 下一篇:如何在 Python 中设置环境变量?

                  相关文章

                  <legend id='6SZrx'><style id='6SZrx'><dir id='6SZrx'><q id='6SZrx'></q></dir></style></legend>

                    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>