Can I create class properties during __new__ or __init__?
<p>I want to do something like this, but I haven't had much success so far.  I would like to make each attr a property that computes _lazy_eval only when accessed:</p>

<pre><code>class Base(object):
    def __init__(self):
        for attr in self._myattrs:
            setattr(self, attr, property(lambda self: self._lazy_eval(attr)))

    def _lazy_eval(self, attr):
        #Do complex stuff here
        return attr


class Child(Base):
    _myattrs = ['foo', 'bar']


me = Child()
print me.foo
print me.bar

#desired output:
#"foo"
#"bar"
</code></pre>

<p>** UPDATE **</p>

<p>This doesn't work either:</p>

<pre><code>class Base(object):
    def __new__(cls):
        for attr in cls._myattrs:
            setattr(cls, attr, property(lambda self: self._lazy_eval(attr)))
        return object.__new__(cls)

#Actual output (it sets both .foo and .bar equal to "bar"??)
#bar
#bar
</code></pre>

<p>** UPDATE 2 **</p>

<p>Used the <code>__metaclass__</code> solution, but stuck it in <code>Base.__new__</code> instead.  It looks like it needed a better defined closure -- "prop()" -- to form the property correctly:</p>

<pre><code>class Base(object):
    def __new__(cls):
        def prop(x):
            return property(lambda self: self._lazy_eval(x))
        for attr in cls._myattrs:
            setattr(cls, attr, prop(attr))
        return object.__new__(cls)

#Actual output!  It works!
#foo
#bar
</code></pre>
