Define class variable in subclass

Hi all

I’m trying to make a subclass inheriting from a superclass. I have a class variable that should be implemented by the subclass.

My code looks like this:

class mybaseclass:
	def hello(self):

class mysubclass(mybaseclass):
	myclassvar = 5
zzz = mysubclass()

Unfortunately, when executing it complains that myclassvar is not defined (see below). But it is defined! It is defined in the subclass. And it will/must be defined in all other subclasses of mybaseclass. How should I do this?

Traceback (most recent call last):
File “C:…\”, line 9, in
File “C:…\”, line 3, in hello
NameError: name ‘myclassvar’ is not defined

It’s an attribute of the class, not instantiated into the function’s namespace. Perhaps you just want:

1 Like

Excellent, that’s it!
Thanks a lot!