首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >不确定为什么路径只存在于while循环的一部分

不确定为什么路径只存在于while循环的一部分
EN

Stack Overflow用户
提问于 2019-05-14 02:14:33
回答 1查看 62关注 0票数 0

在while循环中的某个点,我对一个包含三个项目的索引运行os.listdir以生成一个文件列表,并得到"Windows Error 3- Path get“,尽管我之前已经在脚本中成功地调用了这个路径。

之后,我对它运行了一个os.path.exists,它显示在前两个循环中,目录的计算结果为False,但在第三个循环中,它的计算结果为True。

我试过使用glob.glob,它也只在第三次循环时返回文件。

问题出在“基于找到的镜头数创建读取节点”注释下的while循环中。

如果能帮助我们从一开始就把它理解为True,我们将不胜感激,谢谢!

代码语言:javascript
复制
# Iterating using while loop, this gets every version folder for each shots' plates and stores to a "version" list 

while shotIndex < shotAmountTotal: 
    nextShot = (shots[shotIndex]) 
    shotIndex += 1
    verSearchPath = shotSearchPath + '/' + nextShot + '/' + compFolder + '/' + platesFolder
    foundVerList = os.listdir(verSearchPath)
    verListCombined.append(foundVerList)
    verListSorted = list(chain.from_iterable(verListCombined))



#this groups the like folder names, splits them at the underscore before the version number and then returns only the highest version number of each group

    groupedShotFolders = groupby(verListSorted, key=lambda version: version.rsplit('_', 1)[0])
    latestShotVer = [sorted(group, reverse=True)[0] for key, group in groupedShotFolders]


#creates Read nodes based on number of shots found

latestShotAmount = len(latestShotVer)
latestShotIndex = 0

while latestShotIndex < latestShotAmount:
    latestShot = (latestShotVer[latestShotIndex])
    frameListerPath = verSearchPath + '/' + latestShot + '/' + fileExtension + '/'
    print os.path.exists(frameListerPath)        

    frameLister = os.listdir(verSearchPath + '/' + latestShot + '/' + fileExtension + '/')

我得到的终端输出是:

代码语言:javascript
复制
Result: False
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_010_BG_001_v002/exr/
[]
False
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_010_FG_001_v003/exr/
[]
True
E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr/
['E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.0999.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1000.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1001.exr', 'E:/projects/MBR/shots/103/MRS_103_005_020/2d/plates/MRS_103_005_020_BG_001_v003/exr\\MRS_103_005_020_BG_001_v003.1002.exr']
EN

回答 1

Stack Overflow用户

发布于 2019-05-14 13:29:42

好吧,我会把这个问题归结为用户错误。首先,我切换到"for“和"join”方法来清理一些东西。接下来,我发现前面代码中的"nextShot“变量没有正确迭代,因此它只输出迭代的最后一项,这就是为什么前两个路径的计算结果为False。我通过将"latestShot“变量放在它的位置并修剪掉描述符来修复这个问题。

为了避免使用"os.listdir“时出现的双斜杠,我将其拆分并使用正斜杠重新连接。

感谢您对此的思考和指导。

代码语言:javascript
复制
for latestShot in latestShotVer:
    nuke.createNode("Read", inpanel = False)
    frameListerPath = os.path.join(shotSearchPath, latestShot[:-12], compFolder, platesFolder, latestShot, fileExtension)
    flsplit = frameListerPath.split('\\')
    fljoin = '/'.join(flsplit)
    frameListerPath = fljoin
    frameLister = os.listdir(frameListerPath)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56117793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档