2013-04-10 165 views
0

我想通过2个列表循环,然后加入它们。但是我在构建循环代码时遇到了问题。列表的循环列表

这是Softimage(动画3D程序)代码,但我希望它是有道理的。

这是我有:

import os 
import glob 
app = Application 
storeSelect=[] 
mypath = app.ActiveProject.ActiveScene.filename.value 
folder=[] 
storeAll=[] 
listObj=[] 
path=[] 
storeSelecte=[] 
folderAll=[] 
#Seleccion 
app.SelectObj("*.geometry_cache_grp*") 
mySelection = app.Selection 


# GETS PATHS FOr each Character Folder 

userPath=Application.XSIInputBox ("Direccion de Cache", "Cache")+ "/" 
os.chdir(userPath) 


#/loops 

for lis in mySelection: 
    storeSelect.append(lis) 
    members = app.SelectMembers(lis) 
    app.SelectObj("*.geometry_cache_grp*") 
    mySelection = app.Selection 

    for files in sorted(glob.glob("*.scn_c*")): 
     folder=files 
     for lise in members: 
      print lise,folder 

但我得到的结果的两倍,这样的:

# DI_CACHE.lengua Anim_2p.scn_c_DI_rig 
# DI_CACHE.vidrios Anim_2p.scn_c_DI_rig 
# DI_CACHE.dientes_abajo Anim_2p.scn_c_DI_rig 
# DI_CACHE.lengua Anim_2p.scn_c_TOTO_GALLO_rig 
# DI_CACHE.vidrios Anim_2p.scn_c_TOTO_GALLO_rig 
# DI_CACHE.dientes_abajo Anim_2p.scn_c_TOTO_GALLO_rig 
# TOTO_GALLO_cache.lengua Anim_2p.scn_c_DI_rig 
# TOTO_GALLO_cache.dientes_01 Anim_2p.scn_c_DI_rig 
# TOTO_GALLO_cache.plumas_guantes Anim_2p.scn_c_DI_rig 
# TOTO_GALLO_cache.lengua Anim_2p.scn_c_TOTO_GALLO_rig 
# TOTO_GALLO_cache.dientes_01 Anim_2p.scn_c_TOTO_GALLO_rig 
# TOTO_GALLO_cache.plumas_guantes Anim_2p.scn_c_TOTO_GALLO_rig 

有谁知道怎么纠正我的循环,所以它只能通过它去仅一次)?结果应该是这样的:

# DI_CACHE.lengua Anim_2p.scn_c_DI_rig 
# DI_CACHE.vidrios Anim_2p.scn_c_DI_rig 
# DI_CACHE.dientes_abajo Anim_2p.scn_c_DI_rig 
# TOTO_GALLO_cache.lengua Anim_2p.scn_c_TOTO_GALLO_rig 
# TOTO_GALLO_cache.dientes_01 Anim_2p.scn_c_TOTO_GALLO_rig 
# TOTO_GALLO_cache.plumas_guantes Anim_2p.scn_c_TOTO_GALLO_rig 
+0

你没有得到的东西,TOTO在所有? – Serdalis 2013-04-10 01:01:13

+2

你最好展示这两个原始列表。 – Sheng 2013-04-10 01:03:07

+0

它看起来像你正在重复使用相同的变量名称的两个循环,是故意的?你可以尝试修复,看看结果是不同的。 – 2013-04-10 01:03:09

回答

0

我不知道,如果它可以帮助你,但你可以这样做:

members=[["DI_CACHE.lengua","DI_CACHE.vidrios","DI_CACHE.dientes_abajo"],["TOTO_GALLO_cache.lengua","TOTO_GALLO_cache.dientes_01","TOTO_GALLO_cache.plumas_guantes"]]' 

folders=[["Anim_2p.scn_c_DI_rig"],["Anim_2p.scn_c_TOTO_GALLO_rig"]] 

然后

for i in xrange(len(a)): 
    for n,m in itertools.product(a[i],b[i]): 
     print n,m 

结果:

DI_CACHE.lengua Anim_2p.scn_c_DI_rig 
DI_CACHE.vidrios Anim_2p.scn_c_DI_rig 
DI_CACHE.dientes_abajo Anim_2p.scn_c_DI_rig 
TOTO_GALLO_cache.lengua Anim_2p.scn_c_TOTO_GALLO_rig 
TOTO_GALLO_cache.dientes_01 Anim_2p.scn_c_TOTO_GALLO_rig 
TOTO_GALLO_cache.plumas_guantes Anim_2p.scn_c_TOTO_GALLO_rig 
+0

@ user2250175:如何选择这个答案,但它被张贴为问题[这里](http://stackoverflow.com/questions/15928701/looping -two-lists-of-lists)? – Schorsch 2013-05-08 13:53:37

+0

WTF!完全奇怪! – Moj 2013-05-08 14:21:56