<div class="gmail_quote">On Mon, Dec 13, 2010 at 11:08 AM, Sean Carolan <span dir="ltr">&lt;<a href="mailto:scarolan@gmail.com">scarolan@gmail.com</a>&gt;</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&#39;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>
    &#39;&#39;&#39; This function grabs facter data and sucks it into a dictionary<br>
    called dataMap &#39;&#39;&#39;<br>
    os.system(&#39;facter --yaml &gt; /tmp/sysdata.yaml&#39;)<br>
    f = open(&#39;/tmp/sysdata.yaml&#39;)<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&#39;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>