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