Why is it considered bad practice to hardcode the name of a class inside that class's methods?
<p>In python, why is it a bad thing to do something like this:</p>

<pre><code>class Circle:
  pi = 3.14159 # class variable
  def __init__(self, r = 1):
    self.radius = r
  def area(self):
    return Circle.pi * squared(self.radius)

def squared(base): return pow(base, 2)
</code></pre>

<p>The area method could be defined as follows:</p>

<pre><code>def area(self): return self.__class__.pi * squared(self.radius) 
</code></pre>

<p>which is, unless I'm very much mistaken, considered a better way to reference a class variable. The question is why? Intuitively, I don't like it but I don't seem to completely understand this.</p>

<p>I can name here two reasons </p>

<p>Inheritance</p>

<pre><code>class WeirdCircle(Circle):
    pi = 4

c = WeirdCircle()
print(c.area()) 
# returning 4 with self.__class__.pi 
# and 3.14159 with Circle.pi
</code></pre>

<p>When you want to rename the class, there is only one spot to modify. </p>

python oop