Python subclassing and parent value assignment
<p>Apologies if the subject isn't accurate, I wasn't sure how else to phrase it.</p>

<p>I'm learning to work with Python classes. I created a class that I want to be able to subclass. The problem is that some parts of the class are dependent on variables set in the class, and those default to empty values (the intent is to define them when subclassed). For example:</p>

<p>config.py:</p>

<pre><code>class Config(object):
    VAR1 = ''
    if VAR1 == 'somevalue':
        VAR2 = VAR1 + 'something'
    else:
        VAR2 = VAR1
</code></pre>

<p>subclass.py:</p>

<pre><code>from config import Config
class Production(Config):
    VAR1 = 'value1'
</code></pre>

<p>The problem here is that VAR2 doesn't pick up the subclassed VAR1. I understand why this isn't working as I want, my question is: <strong>Is it possible to do it this way (or in a similar fashion)? And, if so, how?</strong></p>

<p><strong>UPDATE:</strong></p>

<p>I worked out a way to this, but it still requires more typing than I'd prefer--the variations to the function below are minimal and are based on variables that are explicitly set when <code>Config</code> is subclassed. So it would be nice to have these values (VAL2 from the parent class) set automatically based on the context of the subclass (the value of VAL1 when <code>Config</code> is subclassed), rather than having to explicitly set them. </p>

<p>config.py:</p>

<pre><code>class Config(object)
    VAR1 = ''
    VAR2 = ''

def set_var2(val):
    if val == 'somevalue':
        VAR2 = val + 'value2'
    else:
        VAR2 = 'value2'

    return VAR2
</code></pre>

<p>subclass.py:</p>

<pre><code>from config import Config, set_var2
class Production(Config):
    VAR1 = 'value1'
    VAR2 = set_var2(VAL1)
</code></pre>