Re: Example request

Kirill Simonov <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
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: [email protected] <mailto:[email protected]>
> 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: [email protected]
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

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.