• <legend id='IgRXf'><style id='IgRXf'><dir id='IgRXf'><q id='IgRXf'></q></dir></style></legend><tfoot id='IgRXf'></tfoot>
      <bdo id='IgRXf'></bdo><ul id='IgRXf'></ul>
    1. <small id='IgRXf'></small><noframes id='IgRXf'>

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

        如何在 Python 中将环境变量评估为字符串?

        How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)

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

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

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

                  问题描述

                  我有一个代表路径的字符串.因为这个应用程序在 Windows、OSX 和 Linux 上使用,我们已经定义了环境变量来正确映射来自不同文件系统的卷.结果是:

                  I have a string representing a path. Because this application is used on Windows, OSX and Linux, we've defined environment variables to properly map volumes from the different file systems. The result is:

                  "$C/test/testing"
                  

                  我想要做的是评估字符串中的环境变量,以便将它们替换为各自的卷名.是否有我遗漏的特定命令,或者我必须采取 os.environ.keys() 并手动替换字符串?

                  What I want to do is evaluate the environment variables in the string so that they're replaced by their respective volume names. Is there a specific command I'm missing, or do I have to take os.environ.keys() and manually replace the strings?

                  推荐答案

                  使用 os.path.expandvars 展开字符串中的环境变量,例如:

                  Use os.path.expandvars to expand the environment variables in the string, for example:

                  >>> os.path.expandvars('$C/test/testing')
                  '/stackoverflow/test/testing'
                  

                  这篇关于如何在 Python 中将环境变量评估为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  env: python: No such file or directory(env: 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% 就足够了)
                  Why can#39;t environmental variables set in python persist?(为什么python中设置的环境变量不能持久化?)
                        <tbody id='dQp1X'></tbody>
                    • <i id='dQp1X'><tr id='dQp1X'><dt id='dQp1X'><q id='dQp1X'><span id='dQp1X'><b id='dQp1X'><form id='dQp1X'><ins id='dQp1X'></ins><ul id='dQp1X'></ul><sub id='dQp1X'></sub></form><legend id='dQp1X'></legend><bdo id='dQp1X'><pre id='dQp1X'><center id='dQp1X'></center></pre></bdo></b><th id='dQp1X'></th></span></q></dt></tr></i><div id='dQp1X'><tfoot id='dQp1X'></tfoot><dl id='dQp1X'><fieldset id='dQp1X'></fieldset></dl></div>

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

                    • <tfoot id='dQp1X'></tfoot><legend id='dQp1X'><style id='dQp1X'><dir id='dQp1X'><q id='dQp1X'></q></dir></style></legend>

                            <bdo id='dQp1X'></bdo><ul id='dQp1X'></ul>