这段代码片段怎么可能...
def subInPath(origPath, subPath):
origSplit = split(origPath, '/')
subSplit = split(subPath, '/')
subRoot = subSplit[0]
origSplit.reverse()
print origSplit.index(subRoot)
rootIndex = origSplit.index(subRoot)
origSplit[:rootIndex+1] = []
origSplit.reverse()
newPath = join(origSplit, sep)
newPath += (sep + subPath)
if not exists(newPath):
raise Exception, "Path subbed in not found."
return newPath
使用参数 ("C:/Users/MyName/Desktop/second_stage/Kickle_Pack/GardenLand_D.xml", "Kickle_Pack/Animations/TileAnims_48x48.xml")
...
在打印语句处输出2
,但在其下面的语句处抛出ValueError
。我很困惑。
最佳答案
在处理目录或路径时,始终使用 os.path 模块。它具有处理目录所需的所有方法,并且具有兼容多种操作系统的优点。
这只是更好的软件工程。
关于python - 赋值引发 list.index 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3818923/