Computed static property in python
<p>Is it possible to have a static property on a class that would be computed as a one off. The idea would be to be able to do it like so:</p>

<pre><code>class Foo:
    static_prop = Foo.one_off_static_method()

    @staticmethod
    def one_off_static_method():
        return 'bar'
</code></pre>

<p>I thought of using <code>__new__</code> as well.</p>

<pre><code>Class Foo:
    def __new__(cls):
         cls.static_prop = ... do everything here
</code></pre>

<p>Not sure the implications of that though.</p>

<p>Until the class is actually created, <code>one_off_static_method</code> is just a regular function. It needs to be defined before you attempt to call it, since you want to call it while the <code>class</code> statement is being executed. Once you are done with it, you can simply delete it.</p>

<pre><code>class Foo:
    def _one_off_static_method():
        return 'bar'

    static_prop = _one_off_static_method()
    del _one_off_static_method
</code></pre>

python static-methods