【问题标题】:Can I find the path of the executable running a python script from within the python script?我可以从 python 脚本中找到运行 python 脚本的可执行文件的路径吗?
【发布时间】:2010-04-22 14:24:19
【问题描述】:

有没有办法检索正在运行当前 python 脚本的可执行文件的路径(从 python 脚本中)?

【问题讨论】:

    标签: python introspection


    【解决方案1】:

    这应该做你想要的

    >>> import sys
    >>> sys.executable
    'C:\\Python26\\python.exe'
    
    >>> import os
    >>> os.path.dirname(sys.executable)
    'C:\\Python26'
    

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      相关资源
      最近更新 更多