简体   繁体   English

我希望能够从列表python分组相同的文件序列

[英]I want to be able to group same file sequence from a list python

Working on a python function which parses a file containing a list of strings. 使用python函数解析包含字符串列表的文件。 Basically a walked folder structure parsed to a txt file so I don't have to work on real raid while in prod. 基本上是将步行文件夹结构解析为txt文件,因此我在制作产品时不必进行真正的突袭检查。 That is also a requirement. 这也是一个要求。 To work from a txt file containing list of paths. 从包含路径列表的txt文件中工作。

lpaths  =[
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot012/render/SC11_1_Shot012.v01_1025.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot012/render/SC11_1_Shot012.v01_1042.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot012/render/SC11_1_Shot012.v01_1016.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot012/2d/app/Shot012_v1.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot012/2d/app/Shot012_v02.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/3d/app2/workspace.cfg',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/3d/app2/scenes/SC11_1_Shot004_v01.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/3d/app2/scenes/Shot004_camera_v01.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/render/SC11_1_Shot004.v01_1112.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/render/SC11_1_Shot004.v01_1034.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/render/SC11_1_Shot004.v02_1116.exr',
    '/projects/0100/dbu/shots/11_1/SC11_1_Shot004/render/SC11_1_Shot004.v02_1126.exr'
    ]

This is partial list of the cleaned list version ive already worked out and works fine. 这是已经制定并且可以正常使用的清除列表版本ive的部分列表。

The real problem, need to parse all frames from a folder to into a list so it can hold a proper listed sequence. 真正的问题是,需要将文件夹中的所有帧解析为一个列表,以便它可以容纳适当的列出序列。 There could be 1 frame or 1000, also there are multiple sequences in same folder as seen in the list. 如列表中所示,同一文件夹中可能有1帧或1000,也有多个序列。

My goal is to have a list for each sequence in a folder, so I can push them ahead to do more work down the road. 我的目标是在文件夹中为每个序列提供一个列表,这样我就可以推动它们前进以做更多的工作。

Code: 码:

groups = [list(group) for key, group in itertools.groupby(sorted(lpaths), len)]

pp.pprint(groups)

Since you seem to have differing naming conventions you need to write a function that takes a single string and, possibly using regular expressions , returns an unambiguous key for you to sort on, lets say that you names are critically identified by the shot number which can be identified by r".*[Ss]hot_?(\\d+).*\\.ext" you could return an integer for the match base 10 so discarding any leading 0s. 由于您似乎有不同的命名约定,因此您需要编写一个函数,该函数采用单个字符串,并且可能使用正则表达式 ,返回一个明确的键供您排序,可以说您的名字由镜头编号严格标识,可以用r".*[Ss]hot_?(\\d+).*\\.ext"标识,您可以为匹配基数10返回一个整数,因此丢弃任何前导0。

Since you also may have a version number you could do a similar operation to get an unambiguous version number, (and possibly only process the latest version of a given shot). 由于您可能还具有版本号,因此可以执行类似的操作来获得明确的版本号(并且可能仅处理给定快照的最新版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM