<div class="gmail_quote">On Mon, Dec 13, 2010 at 11:08 AM, Sean Carolan <span dir="ltr"><<a href="mailto:scarolan@gmail.com">scarolan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi folks:<br>
<br>
I'm trying to define a short function that will import yaml data into<br>
a python dictionary. I am able to do this by dumping my data into a<br>
temporary file and then importing it with yaml.load. I would like to<br>
see if I can eliminate the temporary file and import the data<br>
directly.<br>
<br>
This works fine:<br>
<br>
import yaml<br>
import os<br>
<br>
def grabfacts():<br>
''' This function grabs facter data and sucks it into a dictionary<br>
called dataMap '''<br>
os.system('facter --yaml > /tmp/sysdata.yaml')<br>
f = open('/tmp/sysdata.yaml')<br>
dataMap = yaml.load(f)<br>
f.close()<br>
<br>
Is there an easy way to do this without writing to a temporary file?</blockquote><div><br></div><div>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. </div>
<div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="http://docs.python.org/library/subprocess.html">http://docs.python.org/library/subprocess.html</a></div><div><br></div><div>
that should get you started.</div>
<div>HTH,</div><div>Wayne</div></div>