From: Kirill S. <xi...@ga...> - 2009-11-27 03:23:16
|
Prashanth Padmanabh wrote: > Hello, > I'm a beginner in YAML. > Is there an example written in python that I can follow to read a yaml > config file like the one below and process its data in my program. For > example use the data below to send an email to mail.foobar.net > <http://mail.foobar.net>. How do I extract the MAIL_SERVER value when > writing a python script? > > WEBSITE: > - www.google.com <http://www.google.com> > - www.pyyaml.org <http://www.pyyaml.org> > - www.yahoo.com <http://www.yahoo.com> > > MAIL_SERVER: mail.foobar.net <http://mail.foobar.net> > EMAIL_ADDRESS: fo...@ba... <mailto:fo...@ba...> > STATUS_INTERVAL_MIN: 15 > LOGFILE: webstat.log > Assuming that the file 'config.yaml' contains the following data: WEBSITE: - www.google.com - www.pyyaml.org - www.yahoo.com MAIL_SERVER: mail.foobar.net EMAIL_ADDRESS: fo...@ba... STATUS_INTERVAL_MIN: 15 LOGFILE: webstat.log the following program loads the configuration file and extracts the value of EMAIL_ADDRESS: import yaml config = yaml.load(open('config.yaml')) print config['EMAIL_ADDRESS'] Thanks, Kirill |