recursive traversal of file

Xavier Decoret decoret at graphics.lcs.mit.edu
Fri Aug 15 21:32:26 CEST 2003


I am reading the lines of a file, executing appropriate command if a 
pattern is found. One of the pattern can be a input command whose effect 
should be to #include the file (possibly recursively)

The main loop looks like this:

data=[]

try:
     file = open(fileName)
     line = file.readline()
     while line:
         if matchInputPattern(line,inputFile):
              # help me here to parse inputFile
         elif matchDataPattern(line):
              data.append(1)
         line = file.readline()
except IOError, e:
     print 'I couldn\'t open file name',fileName
     sys.exit(1)

Can you tell me if there is a simple way to do the part that says #help 
me!. Should I do a recursive function?

-- 
+-------------------------------------------------+
| Xavier Décoret - Post Doct			  |
| Graphics Lab (LCS) - MIT			  |
| mailto: decoret at graphics.lcs.mit.edu		  |
| home  : http://www.graphics.lcs.mit.edu/~decoret|
+-------------------------------------------------+





More information about the Python-list mailing list