Can variables have synonyms?
<p>I have very big string, which give me access to my dictionary in another dictionary in another class.</p>

<pre><code>self.app_data.ip_table[self.app_data.cfg.MY_IP]['tasks']
</code></pre>

<p>If I used this dict in sequence of strings, I can write something like this (I think so):</p>

<pre><code>with self.app_data:
    ...
</code></pre>

<p>But I use this variable in different lines in all file, I can't use <code>with</code> instruction. Than I think, in C++ we can use something like <code>#define VAR very.long.access.path.to.variable</code>.</p>

<p>Is there something like that in python? Can I shorter variable access name?</p>

<p>P.S.
That long-access-name variable changes with other thread. I don't need just assigned it to another variable. I'm looking for text-shorter for code</p>

<p>Use properties maybe?</p>

<pre><code>class C:
    def __init__(self, ...):
        self.app_data = get_app_data()

    @property
    def var(self):
        return self.app_data.very['long'].path.here

    @var.setter
    def var(self, value):
        self.app_data.very['long'].path.here = value

c = C()
print c.var
c.var = 1337
</code></pre>

<p>Also you can create <code>var_threadsafe</code> property with a mutex inside if you expect this data to be read/written in multiple threads.</p>

python python-2.7 variables dictionary