IOError:[Errno 22]无效模式('r')或文件名:''

时间:2013-01-30 05:25:14

标签: python file-io

任何人都可以指出代码中有什么问题吗?为什么我得到无效模式('r')错误?我确保我传递的文件存在于该位置......

我只是编写一个小程序来构建和遍历python中的树数据结构。 感谢您的帮助!!

 import re, os, sys
_inputFileApp = './sampleCatalog/Apps/Parent00.app'

class Node(object):
    def __init__(self, isRoot=False, isSubGroup=False, execOrder=0,\
                 groupName='', progName='', children=[]):
        self.isRoot = isRoot
        self.isSubGroup = isSubGroup
        self.execOrder = execOrder
        self.groupName = groupName
        self.progName = progName
        self.children = children

    def addChild(self, obj):
        self.children.append(obj)

def main():
    ro=Node()
    readAppFile(_inputFileApp,ro)

#reads and .app File and returns list of .app files to track next
def readAppFile(appFileName,ro):
    if(ro is None):
        ro.isRoot=True
        print ro.isRoot
        print ro.children

    # Define the input & output files
    _finput = open(appFileName, 'r')

    # Search criteria
    keywords =['#PROGRAM?']
    pattern = re.compile('|'.join(keywords),re.IGNORECASE)

    #read line-by-line
    line=_finput.readline()
    while line:
        if pattern.search(line):
            child = Node() # Create an empty node of type Nodes

            #Record line 1,2
            child.execOrder=_finput.readline().strip()
            child.isSubGroup=_finput.readline().strip()
            #Skip 2 lines
            for i in range(1,3):
                _finput.readline()
            #Record line 5,6
            child.groupName=_finput.readline().strip()
            child.programName=_finput.readline().strip()
            #r.addChild(child)
            if(child.isSubGroup):
                readAppFile(child.groupName,child)
        line=_finput.readline()
    _finput.close()
    return ro



if __name__ == "__main__":
    sys.exit(main())

0 个答案:

没有答案