Marching on: populating lists or tuples from textfiles - manipulating textfiles

Terry Reedy tjreedy at
Wed Aug 28 02:22:47 CEST 2002

"Micah Mayo" <astrophels at> wrote in message
news:57e0b28.0208271327.627d8b0a at
> What I'd like to do is this: Have three 'config' files for the
> to read. The first would tell the program which files to copy, for
> example. Here is the syntax for this one:
> # ServiceName    SourcePath         DestinationPath
> BIND             /mnt/named.conf -> /etc/namedb/named.conf
> BIND             /mnt/ -> /etc/namedb/
> BIND             /mnt/ -> /etc/namedb/
> HTTPD            /mnt/httpd.conf -> /usr/apache2/httpd.conf
> etc..
> etc..
> I'd like python to read that file, populate a list, or possibly a
> tuple with the correct information, and then run my file moving

Call that file movelist and leave out '->' but include space or tab
Then here's a start:

def bind(s,d): #whatever
def httpd(s,d): # ditto

services = { #dispatch dict
  'BIND': bind, # service name to service function binding
 'HTTPD': httpd,

f = file('movelist')
for l in f.readlines:
  ser,src,dst = l.split()
  services[ser](src,dst) # call appropriate funct with two params

Terry J. Reedy

More information about the Python-list mailing list