<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PyTPMOTW: PyYAML</title>
	<atom:link href="http://www.protocolostomy.com/2010/04/12/pytpmotw-pyyaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.protocolostomy.com/2010/04/12/pytpmotw-pyyaml/</link>
	<description>Made with only the finest 1's and 0's</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:20:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: m0j0</title>
		<link>http://www.protocolostomy.com/2010/04/12/pytpmotw-pyyaml/comment-page-1/#comment-38845</link>
		<dc:creator>m0j0</dc:creator>
		<pubDate>Tue, 13 Apr 2010 12:21:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=751#comment-38845</guid>
		<description>&lt;h3&gt;UPDATE&lt;/h3&gt; 
Since posting this comment, I&#039;ve updated the article to include aliases and anchors, so if you already read that, no need to read this. 
&lt;h3&gt;/UPDATE&lt;/h3&gt;

Gah!!! I forgot to add the section on anchors and aliases!!!! 

So, really quick: for anyone reading the comments, you can create a block in your YAML config file, and then reference it in other sections of the configuration. This is done using anchors and aliases. An anchor starts with &quot;&amp;&quot; and an alias (a reference to the anchor) begins with a &quot;*&quot;. So, let&#039;s say you have multiple plugins loaded (continuing on from the example), and they all need their own configuration, but they&#039;ll all connect to the same exact database server, and use the same credentials and db name, etc. Just create the db config once, make it an anchor, and reference it as needed: 

[sourcecode]
DB: &amp;MainDB
   server: localhost
   port: 6000
   user: dbuser
   db: myappdb
Plugins: 
   loghandler: !!python/object/new:MyLogHandler
      args: [&#039;mylogfile.log&#039;]
      db: *MainDB
[/sourcecode]

When this is read in, the dictionary defined in &amp;MainDB will appear as the value for the dict key [&#039;Plugins&#039;][&#039;loghandler&#039;][&#039;db&#039;]. If you wanted to pass the *entire* config structure to your plugin, you technically wouldn&#039;t need this, but I typically would only pass the portion of the config structure specifically dealing with the plugin, because configs can get large, and there could be lots of stuff that have nothing to do with the plugin in the rest of the config.</description>
		<content:encoded><![CDATA[<h3>UPDATE</h3>
<p>Since posting this comment, I&#8217;ve updated the article to include aliases and anchors, so if you already read that, no need to read this. </p>
<h3>/UPDATE</h3>
<p>Gah!!! I forgot to add the section on anchors and aliases!!!! </p>
<p>So, really quick: for anyone reading the comments, you can create a block in your YAML config file, and then reference it in other sections of the configuration. This is done using anchors and aliases. An anchor starts with &#8220;&amp;&#8221; and an alias (a reference to the anchor) begins with a &#8220;*&#8221;. So, let&#8217;s say you have multiple plugins loaded (continuing on from the example), and they all need their own configuration, but they&#8217;ll all connect to the same exact database server, and use the same credentials and db name, etc. Just create the db config once, make it an anchor, and reference it as needed: </p>
<pre class="brush: plain; title: ; notranslate">
DB: &amp;MainDB
   server: localhost
   port: 6000
   user: dbuser
   db: myappdb
Plugins:
   loghandler: !!python/object/new:MyLogHandler
      args: ['mylogfile.log']
      db: *MainDB
</pre>
<p>When this is read in, the dictionary defined in &amp;MainDB will appear as the value for the dict key ['Plugins']['loghandler']['db']. If you wanted to pass the *entire* config structure to your plugin, you technically wouldn&#8217;t need this, but I typically would only pass the portion of the config structure specifically dealing with the plugin, because configs can get large, and there could be lots of stuff that have nothing to do with the plugin in the rest of the config.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juho Vepsäläinen</title>
		<link>http://www.protocolostomy.com/2010/04/12/pytpmotw-pyyaml/comment-page-1/#comment-38824</link>
		<dc:creator>Juho Vepsäläinen</dc:creator>
		<pubDate>Tue, 13 Apr 2010 04:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=751#comment-38824</guid>
		<description>Nice post, m0j0! I find YAML a great match with Python as well. I have used it for UI definitions as it&#039;s most excellent for describing structure. Compared to XML it&#039;s so much nicer to read and write.

Of course you have proper support for schemas in XML ie. but I find YAML superior for many purposes.

I also like JSON (a subset of YAML) a lot.

Btw it is possible to store graphs ie. cyclic structures using YAML in case you use aliases (http://pyyaml.org/wiki/PyYAMLDocumentation#Aliases). I find that utterly cool. :)</description>
		<content:encoded><![CDATA[<p>Nice post, m0j0! I find YAML a great match with Python as well. I have used it for UI definitions as it&#8217;s most excellent for describing structure. Compared to XML it&#8217;s so much nicer to read and write.</p>
<p>Of course you have proper support for schemas in XML ie. but I find YAML superior for many purposes.</p>
<p>I also like JSON (a subset of YAML) a lot.</p>
<p>Btw it is possible to store graphs ie. cyclic structures using YAML in case you use aliases (<a href="http://pyyaml.org/wiki/PyYAMLDocumentation#Aliases" rel="nofollow">http://pyyaml.org/wiki/PyYAMLDocumentation#Aliases</a>). I find that utterly cool. <img src='http://www.protocolostomy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

