On Mon, Dec 13, 2010 at 11:08 AM, Sean Carolan <scaro...@gmail.com> wrote:
> Hi folks: > > I'm trying to define a short function that will import yaml data into > a python dictionary. I am able to do this by dumping my data into a > temporary file and then importing it with yaml.load. I would like to > see if I can eliminate the temporary file and import the data > directly. > > This works fine: > > import yaml > import os > > def grabfacts(): > ''' This function grabs facter data and sucks it into a dictionary > called dataMap ''' > os.system('facter --yaml > /tmp/sysdata.yaml') > f = open('/tmp/sysdata.yaml') > dataMap = yaml.load(f) > f.close() > > Is there an easy way to do this without writing to a temporary file? Presumably you could use something like subprocess and simply pipe stdout to your program. I presume facter --yaml will produce output to stdout? It's fairly trivial to read stdout using subprocess. http://docs.python.org/library/subprocess.html that should get you started. HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor