Using instance variables as named format substitutions
<p>I am writing a Python program that generates a C++ program.  There are a whole bunch of instances of code like this:</p>

<pre><code>class TestBlock(object):
    def __init__(self, mod, name, casetype, generator):
        self.mod = mod
        self.name = name
        self.casetype = casetype
        self.generator = generator

    def fullname(self):
        return "{mod}.{name}".format(**self.__dict__)

    def write_cases(self, outf):
        outf.write("const {casetype} {mod}_{name}[] = {{\n"
                   .format(**self.__dict__))
        for case in self.generator():
            outf.write("  { " + case + " },\n")
        outf.write("};\n\n")
</code></pre>

<p>The <code>"text {subst}".format(**self.__dict__)</code> construction is the only way I have found to make the instance variables of <code>self</code> available as named substitutions, and it's ugly and I do not like it.  I would like to be able to write <code>"text {subst}".format(self)</code>; is this possible, and if so, how?  I'm aware that <code>"text {0.subst}".format(self)</code> will work out of the box and <code>"text {subst}".format(**self)</code> can be made to work with a few special methods, but both of those still have extra gunk.</p>
