How to correctly overload a variable in class inheritance with the same variables
<p>I need to override or overload a variable in a class inheritance. Here is what I am trying to achieve:</p>

<pre><code>class MainClass:
    def __init__(self, a, b, c, d):
        type(a) = str

class MyClass(MainClass):
   def __init__(self, a, b, c, d):
       type(a) = object of one of my classes.
</code></pre>

<p>How do I achieve this in Python 3? I have looked into inheritance but either this type of situation is not discussed or I don't get it.</p>

<p>
So you are trying to <em>reset</em> the variable.<br>
Really, it's the same as creating the variable for the first time.</p>

<pre class="lang-py prettyprint-override"><code>class Base:
    var = 12
class Cls(Base):
    var = 'abc'
</code></pre>

<p>The class's variables are copied when you create a new class, so these variables <strong>belong</strong> the base, but <strong>gotten</strong> from the the new class. The new class redirects to it's base if this variable is not his.  </p>

<p>So, editing the class (<em>see below</em>) makes the function reference to it's class, which references to it's base.</p>

<pre class="lang-py prettyprint-override"><code>class Class(Base):
    def getVar(self):
        return self.var
</code></pre>

<p>Same with editing and deleting.  </p>

<p>To make variables <strong>copy</strong> into the class, there are 2 solutions:  </p>

<p>One:</p>

<pre class="lang-py prettyprint-override"><code>class Base:
    __var = 12
    def __init__(self):
        self.var = self.__var
class Class(Base):
    var = _Base__var #add any methods to copy like list.copy()
    def __init__(self):
        pass
</code></pre>

<p>Two:</p>

<pre class="lang-py prettyprint-override"><code>class Base:
    var = 12
class Class(Base):
    pass
Class.var = Base.var #add any methods to copy like list.copy()
</code></pre>

<p>The first one works because of the rule that variables that start with two or more underscores (_) and don't match &#95;&#95;{name}&#95;&#95; form are renamed to 
_{class name}{variable name}.
Then the &#95;&#95;init&#95;&#95; function creates a variable called var with the value of _Base__var.</p>

<ul>
<li>It is making the object weight more</li>
<li>You need to redefine the &#95;&#95;init&#95;&#95; class</li>
<li>No code outside functions or classes</li>
</ul>

<p>Second one copies it from the outside.  </p>

<ul>
<li>Code outside functions or classes</li>
</ul>

python python-3.x inheritance