0

Soppose such a minimal code:

class Dog:
    kind = 'canine'        
    def __init__(self, name):
        self.name = name   

class TestDog(Dog):
    print(kind)

It comes by error:

NameError: name 'kind' is not defined

Since the class attribute kind is inherited universally,
why NameError reported?

Kevin
  • 74,910
  • 12
  • 133
  • 166
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • Use Dog.kind to access the variable `kind` –  May 02 '18 at 16:08
  • 2
    BTW, your `TestDog` class is a bit odd. We don't normally put executable code like that into a class definition outside a method, except maybe to initialize a class attribute. – PM 2Ring May 02 '18 at 16:13

0 Answers0