ConfigParser question

Carlos Molina cmolina at net-uno.net
Tue Jan 14 18:45:11 CET 2003


Greetings

I'm new to python (i come from perl) and I am doing a little program...
My question is with ConfigParser class..

If I have the following conf file

[dirs]
recursive = /home/cmolina
recursive = /etc
recursive = /tmp/usr

[options]
logfile = ids.loga

and here, the simple code

import ConfigParser,os,getopt,sys
config = ConfigParser.ConfigParser()
config_file = 'test.conf'

def main():
       parse_command_options()
       parse_config()

def parse_config():
      config.read(config_file)
       logfile = config.get('options','logfile')
       # Colocamos en una lista las secciones
       options = config.options('dirs')
       print config.get('dirs','recursive')

def parse_command_options():
       try:
               (options,arguments) = 
getopt.getopt(sys.argv[1:],'d:',['md5','init','check'])
               print "Options: ",options
               print "Arguments: ", arguments
       except getopt.GetoptError,error:
               usage()
               return 0
       if options == []:
               usage()
              def usage():
       print """
       IDS v0.0.1a
       ERROR: Opcion desconocida o no se colocaron argumentos necearios
       Uso: ids.py --md5 --init --check
               --md5
               --init
               --check
       """

If you run the scripot like this

./ids.py --md5

I get this

Options:  [('--md5', '')]
Arguments:  []
/tmp/usr

What happens with the others recursive options values..??
I tried to push the get method to a list, but, always it returns the 
last recursive options values...

IS there a way that I can manage this situation...??

Thanks a lot

Carlos






More information about the Python-list mailing list