How to make a class interfere in another with python [closed]

0

I'm trying to make a switch in kivy style, when one is true, the other is false, but when I change a variable in the first class, it is not changed in the second, and remains with the original value. Explicating:

c = 'NADA'

class A():

        c = 'CLASS A'        

class B():

        print(c)
        c = 'CLASS B'
        print(c)

x = A()
x = B()
print(c)

It has as output:

NADA
CLASS B
NADA
    
asked by anonymous 22.11.2018 / 00:56

1 answer

1

It will be necessary to identify that the variable c that you want to change is of class A() . By using it the way you did, you are changing the global variable created at the beginning of the code.

It would look like this:

c = 'NADA'

class A():
    c = 'CLASS A'        
    print(c)

class B():
    A.c = 'CLASS B'
    print(A.c)

x = A()
x = B()

Resulting in:

CLASS A
CLASS B
    
22.11.2018 / 01:08