Skip to content Skip to sidebar Skip to footer

Accessing Base Class Variable

How do I access id from my child class? class BaseClass: id = 'testing' class MyClass(BaseClass): something = id More specifically, I can't access id from class:User: cla

Solution 1:

Here is a little program to test inheritance in your sample example:

classBaseClass:
    id = 'testing'classMyClass(BaseClass):
    something = BaseClass.idif __name__ == '__main__':
    print(MyClass().something) # >> "testing"

You should be able to replace id with BaseModel.id. If not, please report what error you're getting.

Post a Comment for "Accessing Base Class Variable"