How to evaluate environment variables into a string in Python?

前端 未结 1 879
说谎
说谎 2020-11-29 07:02

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 diffe

相关标签:
1条回答
  • 2020-11-29 07:37

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

    >>> os.path.expandvars('$C/test/testing')
    '/stackoverflow/test/testing'
    
    0 讨论(0)
提交回复
热议问题