开发者

Assignment raises exception for list.index

How could this code fragment...

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

with the arguments ("C:/Users/MyName/Desktop/second_stage/Kickle_Pack/GardenLand_D.xml", "Kickle_Pack/Animations/TileAnims_48x48.xml")...

Output 2 at the print statement, but throw a ValueError at the statement below it. I'm baffled.


Always use os.path module when working with directories or paths. It's got all the methods needed to work with directories, plus it has the advantage of being compatible in multiples operating system.

It's just better software engineering.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜