[Zope] reading text based config file

Casey Duncan cduncan@kaivo.com
Mon, 30 Apr 2001 09:24:26 -0600


"Thomas B. Passin" wrote:
> 
> Do a split on the ':'.  It will give you a list containing the three parts.
> 
> [Marcus Schopen]
> 
> what's the best way to read a flat file like this line by line and split
> each line to three variables?
> 
> 1:menuname:url
> 1.1:submenuname:url
> 1.2:submenuname:url
> 2:nenuname:url
> 2.1:sub
> ...
> 

import string

def readconfig(path):
  f = open(path)
  vars = []
  for line in f.readlines():
    vars.append(string.split(line,':'))
  f.close()
  return vars

You could also use regular expressions, which might be faster, just
harder to read.

-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>