Help needed on config files

Rob Wolfe rw at smsnet.pl
Wed Jan 31 13:59:46 CET 2007


jvdb wrote:
> Hi there,
>
> I am quite new on python programming and need some help on solving my
> problem..
>
> I have to make a (python) program which deletes files from
> directories. I don't think deleting, etc. is the problem. The problem
> is that the directories where i have to delete them are 'dynamic'/
> subject to change. So what i thought is to make a config file
> containing an identifier (useful for myself) and there the directory.
> something like:
> [PROJECTx]
> <path>
> [PROJECTy]
> <path>

What about this?

# proj.cfg
[PROJECTx]
path=/path/to/dir1
[PROJECTy]
path=/path/to/dir2

# cfg.py
from ConfigParser import ConfigParser
cfg = ConfigParser()
cfg.read("proj.cfg")
for proj in cfg.sections():
    path = cfg.items(proj)[0][1]
    print "proj: %s, path: %s" % (proj, path)

Is that not enough?

--
HTH,
Rob




More information about the Python-list mailing list