[Tutor] Recursive search
sessile@in-gen.net
sessile@in-gen.net
Thu, 13 Apr 2000 06:33:23 -0400
Hello,
I am reading a configuration file that can point to other
configuration files with a similar format. Each of those
files can call other such files and so on. Given the first
file, I would like to build a list of all the config files.
I thought a recursive function would do the trick, but I
don't appear to be saving the list of configs properly.
The files may be out of date so I need to test for thier
existance.
The code below seems to print the files out correctly,
but the "configs" list remains empty. Advice appreciated!
Example files:
<file "config.1">
!This is a comment.
include /path/to/some/file
include /path/to/config.2
=====
<file "config.2">
include /bad/file
include /yet/another/file
=====
def getConfigs(file):
configs = []
if not os.path.isfile(file):
print "Not a file: %s" % file
else:
for line in open(file,"r").readlines():
split = map(string.strip, string.split(line))
try:
split[0]
except IndexError:
pass
else:
if split[0] == "include":
print split[-1]
configs.getConfigs(split[-1])
return configs
myconfigs = getConfigs(myconfigfile)
--
E-Mail: sessile@in-gen.net
"I don't want the world... I just want your half."
-- TMBG (Anna Ng)