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>Zen of python says keep your code as simple as possible to make it readable. Why to get into using the class name or super. If you just use self then it will refer the relevant class and print its relevant variable. Refer below code.</p>

<pre><code>class Rectangle(object):
    self.name = "Rectangle"
    def print_name(self):
        print(self.name)

class Square(Rectangle):
    name = 'square'

sq = Square()
sq.print_name
</code></pre>

python oop