Namedtuple like class
<p>I find myself writing this class often in my python code when I need a quick single use class.</p>

<pre><code>class Struct(object):
   def __init__( self, **kwargs ):
      for k in kwargs:
         setattr(self,k,kwargs[k])
</code></pre>

<p>The basic idea is so I can do quick things like this:</p>

<pre><code>foo = Struct( bar='one', baz=1 )
print foo.bar
foo.baz += 1
foo.novo = 42 # I don't do this as often.
</code></pre>

<p>Of course this doesn't scale well and adding methods is just insane, but even so I have enough data-only throw-away classes that I keep using it.</p>

<p>This is what I thought <a href="http://docs.python.org/library/collections.html#collections.namedtuple" rel="nofollow">namedtuple</a> was going to be.  But the namedtuple's syntax is large and unwieldy.</p>

<p>Is there something in the standard library I haven't found yet that does this as well or better?</p>

<p>Is this bad bad style? or does it have some hidden flaw?</p>

<h3>update</h3>

<p>Two concrete example to show why I don't just use a dict.  Both of these examples <em>could</em> be done with a dict but it obviously non-idiomatic.</p>

<pre><code>#I know an order preserving dict would be better but they don't exist in 2.6.
closure = Struct(count=0)
def mk_Foo( name, path ):
   closure.count += 1
   return (name, Foo( name, path, closure.count ))

d = dict([
   mk_Foo( 'a', 'abc' ),
   mk_Foo( 'b', 'def' ),
   # 20 or so more
   ] )


@contextmanager
def deleter( path ):
   control = Struct(delete=True,path=path)
   try:      
      yield control
   finally:
      if control.delete:
         shutil.rmtree(path)

with deleter( tempfile.mkdtemp() ) as tmp:
   # do stuff with tmp.path

   # most contexts don't modify the delete member
   # but occasionally it's needed
   if keep_tmp_dir:
      tmp.delete = False
</code></pre>
