How to make one class interfere with another with python

Asked

Viewed 46 times

0

I want to make a switch button with kivy style, when one is true, the other is false, however, when I change a variable in the class of the first, it is not changed in the second, and remains with the original value. Exemplifying:

c = 'NADA'

class A():

        c = 'CLASS A'        

class B():

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

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

Has as output:

NADA
CLASS B
NADA
  • What is the result you expect?

  • Sorry, I ended up not making explicit, but it’s like the friend below showed, CLASS A CLASS B

1 answer

2


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.