<br><div><div class="gmail_quote">On Sat, Feb 7, 2009 at 10:57 AM, Brantley Harris <span dir="ltr"><<a href="mailto:deadwisdom@gmail.com">deadwisdom@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
So it's easy enough to declare properties on classes, but rather<br>
difficult to do so on objects themselves (I'm not even sure it's<br>
possible, well not good form anyhow.)<br>
<br>
So you have a few options. One is to subclass your Encoder with an<br>
intermediate class, and then add properties, dynamically to it:<br>
class LameEncoder(Encoder):<br>
@classmethod<br>
def add_property(cls, attr, default):<br>
def setter(self, v):<br>
setattr(self, '_%s' % attr, v)<br>
def getter(self):<br>
return getattr(self, '_%s' % attr, default)<br>
setatter(cls, attr, property(gettter, setter))<br>
<br>
for attr, default in PARAMETER_LIST:<br>
LameEncoder.add_property(atter, default)<br></blockquote></div><br></div><div>I went with the first method you suggested and it worked perfectly. Thanks!</div><div><br></div><div>-Tim Gebhardt</div><div><a href="mailto:tim@gebhardtcomputing.com">tim@gebhardtcomputing.com</a></div>
<div><br></div>