0

由于我同时使用 Windows'和cmd.exemsysgit bash尝试访问 Windows-path 输出os.getcwd()导致 Python 尝试访问以驱动器号和冒号开头的路径,例如C:\,它bash正确确定了无效的 unix-path,而应该从/c/这个例子开始。但是,如果脚本在其中运行,我如何修改 Windows 路径以使其等效于bash

4

1 回答 1

0

SHELL=bash丑陋但应该可以工作,除非您为 Windows创建环境变量:

def msysfy(dirname):
    import os
    try:
        shell = os.environ['SHELL']
    except KeyError:  # by default, cmd.exe has no SHELL variable
        shell = 'win'
    if os.path.basename(shell)=='bash' and dirname[1] == ':':
        return '/' + dirname[0].lower() + '/' + dirname[2:]
        # don't worry about the other backslashes, msys handles them
    else:
        return dirname
于 2016-05-18T08:02:58.653 回答