Help with ConfigParser

Jorge Godoy godoy at ieee.org
Sun May 2 07:58:23 EDT 2004


On Dom 02 Mai 2004 08:49, Stephen Boulet wrote:

> I'm having a bit of trouble getting my head around the ConfigParser
> module. I have a very simple configuration file; maybe the easiest thing
> to do would be to show that:
> 
> ============
> # Add a local directory to be backed up followed
> # by the directory name on the FTP server.
> #
> # Example: /home/joe/digital photos = photos
> 
> [Backups]
> /home/stephen/photos/digital camera = photos
> /home/stephen/documents/tax documents = taxes
> ============
> 
> I just want to retrieve the information in the backups section. Thanks.

Which one? ;-) There are two.

You can list the keys (LHS) and the values (RHS) or both. 


>>> import ConfigParser
>>> configFile = open('/etc/g2ctech/cvs.cf')
>>> config = ConfigParser.ConfigParser()
>>> config.readfp(configFile)
>>> config.items('default')
[('forbidden_exts', "['.doc', '.xls', '.ppt']"), ('cvsroot', '/home/cvs')]
>>> config.items('get_data_from_mail')
[('maildir',
'/home/godoy/empresa/clientes/dataprev/cvs-import/tests/sample')]
>>> config.get('default', 'cvsroot')
'/home/cvs'
>>>
 

Default is a section as well as get_data_from_mail.


Be seeing you,
-- 
Godoy.      <godoy at ieee.org>



More information about the Python-list mailing list