2013-04-06 68 views
0

我在maya 2012中得到这个错误,不知道如何解决,我试图在搜索文件夹中的其他文件时让python忽略init文件。任何建议将不胜感激。TypeError:'NoneType'对象不可迭代

Error: 'NoneType' object is not iterable 
Traceback (most recent call last): 
    File "<maya console>", line 18, in <module> 
    File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\blueprint_UI.py" line 28, in __init__ 
    self.initialiseModuleTab(tabHeight, tabWidth) 
    File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\blueprint_UI.py", line 50, in initialiseModuleTab 
    for module in utils.findAllModules("Modules/Blueprint"): 
    File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\utils.py", line 8, in findAllModules 
    for file in allPyFiles: 
TypeError: 'NoneType' object is not iterable 

主要代码是

import maya.cmds as cmds 

import System.utils as utils 
reload(utils) 

class Blueprint_UI: 
    def __init__(self): 
     # Store UI elements in a dictionary 
     self.UIElements = {} 

     if cmds.window("blueprint_UI_window", exists=True): 
      cmds.deleteUI("blueprint_UI_window") 

     windowWidth = 400 
     windowHeight = 598 

     self.UIElements["window"] = cmds.window("blueprint_UI_window", width=windowWidth, height=windowHeight, title="Blueprint Module UI", sizeable=False) 

     self.UIElements["topLevelColumn"] = cmds.columnLayout(adjustableColumn=True, columnAlign="center") 

     # Setup tabs 
     tabHeight = 500 
     self.UIElements["tabs"] = cmds.tabLayout(height=tabHeight, innerMarginWidth=5, innerMarginHeight=5) 

     tabWidth = cmds.tabLayout(self.UIElements["tabs"], q=True, width=True) 
     self.scrollWidth = tabWidth - 40 

     self.initialiseModuleTab(tabHeight, tabWidth) 

     cmds.tabLayout(self.UIElements["tabs"], edit=True, tabLabelIndex=([1, "Modules"])) 


     # Display window 
     cmds.showWindow(self.UIElements["window"]) 

    def initialiseModuleTab(self, tabHeight, tabWidth): 
     scrollHeight = tabHeight # temp value 

     self.UIElements["moduleColumn"] = cmds.columnLayout(adj=True, rs=3) 

     self.UIElements["moduleFrameLayout"] = cmds.frameLayout(height=scrollHeight, collapsable=False, borderVisible=False, labelVisible=False) 

     self.UIElements["moduleList_Scroll"] = cmds.scrollLayout(hst=0) 

     self.UIElements["moduleList_column"] = cmds.columnLayout(columnWidth = self.scrollWidth, adj=True, rs=2) 

     # First separator 
     cmds.separator() 

     for module in utils.findAllModules("Modules/Blueprint"):  
      print module 

,搜索文件夹内的文件代码:

def findAllModules(relativeDirectory): 
    # Search the relative directory for all available modules 
    # Return a list of all module names (excluding the ".py" extension) 
    allPyFiles = findAllFiles(relativeDirectory, ".py") 

    returnModules = [] 

    for file in allPyFiles: 
     if file != "__init__": 
      returnModules.append(file) 

    return returnModules  


def findAllFiles(relativeDirectory, fileExtension): 
    # Search the relative directory for all files with the given extension 
    # Return a list of all file names, excluding the file extension 
    import os 

    fileDirectory = os.environ["RIGGING_TOOL_ROOT"] + "/" + relativeDirectory + "/" 

    allFiles = os.listdir(fileDirectory) 

    # refine all files, listing only those of the specified file extension 
    returnFiles = [] 
    for f in allFiles: 
     splitString = str(f).rpartition(fileExtension) 

     if not splitString[1] == "" and splitString[2] == "": 
      returnFiles.append(splitString[0]) 


     print returnFiles 

当我内主要添加以下代码它打破

for module in utils.findAllModules("Modules/Blueprint"): 

也是__init__文件搜索代码中如果我添加底部代码中,我得到的错误

returnModules = [] 

for file in allPyFiles: 
    if file != "__init__": 
     returnModules.append(file) 

return returnModules 

我不知道我究竟是如何得到NoneType错误,因为底部的两个代码看起来是正确的我任何人都可以帮忙吗?

回答

2

print returnFiles更改为return returnFiles

+0

感谢您的帮助,它的工作;) – user2251651 2013-04-06 20:02:53

1

你没有从findAllFiles()返回returnFiles,所以它返回None - 这是不可迭代的。