Re: Help needed on config files




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

.



Relevant Pages

  • Help needed on config files
    ... I am quite new on python programming and need some help on solving my ... [PROJECTx] ... a config file, but only when you know the key.. ...
    (comp.lang.python)
  • Re: Help needed on config files
    ... I am quite new on python programming and need some help on solving my ... [PROJECTx] ... a config file, but only when you know the key.. ... The classes defined in the ConfigParser module contain a 'sections' ...
    (comp.lang.python)