分配引发异常列表.索引

2024-05-13 21:19:14 发布

您现在位置:Python中文网/ 问答频道 /正文

这个代码片段怎么可能。。。你知道吗

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")。。。你知道吗

在print语句处输出2,但在它下面的语句处抛出一个ValueError。我很困惑。你知道吗


Tags: indexnotseppackreversesplitprintsubpath
1条回答
网友
1楼 · 发布于 2024-05-13 21:19:14

在处理目录或路径时始终使用os.path模块。它拥有处理目录所需的所有方法,而且它还具有在多个操作系统中兼容的优势。你知道吗

这只是更好的软件工程。你知道吗

相关问题 更多 >