title: Modifying python's string Formatter
body: <p>I have a function which takes no arguments and returns a string, which I want to be called using a string format. Here it is, and here's how I've tried to use <a href="http://docs.python.org/3/library/string.html#string.Formatter.format" rel="noreferrer"><code>format</code></a>:</p>
  
  <pre><code>def cabbages():
      return 'hello'
  
  In [2]: '{cabbages} world'.format(**locals())
  Out[2]: '&lt;function cabbages at 0x101f75578&gt; world'
  
  In [3]: '{cabbages()} world'.format(**locals())
  KeyError: 'cabbages()'
  </code></pre>
  
  <p><em>So neither of which is quite what I want, i.e. the value of <code>cabbages()</code>.</em></p>
  
  <p><a href="http://www.python.org/dev/peps/pep-3101/" rel="noreferrer">PEP 3101</a> describes some way in which <code>string.Formatter</code> can be overwritten but it doesn't seem to give many examples. How can I subclass/customise the string <a href="http://docs.python.org/3/library/string.html#string.Formatter" rel="noreferrer"><code>Formatter</code></a> class to do this?</p>
  
  <p><em>A hacky thing I considered would be to overwrite the <code>__getattr__</code> method of <code>cabbages</code>, and I <strong>really</strong> don't want be "considered pathological" (or, at least, *that* pathological).</em></p>