Python class and variable issue(newby question!)

Sam Berry sambez_14 at hotmail.co.uk
Fri Mar 29 17:12:01 EDT 2013


Hey, 

Im new to object orientated programming and have an issue with using classes. Im using the kivy module, a GUI creator , so posting the actual code may confuse. But an example of what im trying to achieve is below

class test()
    s = 1
    
    def test1()
        global s
        s = 2

    def test2()
        global s
        s = 3

    def test3()
        global s
        s = 4


class test4()

    def printing()
        print test().s

After been in the test()class  a choice of buttons allows the user to run either of the functions within it and sends us into the test4() class. Then another button runs printing().

However printing() always prints 1, even if the variable has been changed. Im guessing because  print test().s  redefines the variable. May be a very simple to solve problem, but i cant figure it out.

Any insights of how to get this working, or example code would be very helpful!

Thanks, Sam



More information about the Python-list mailing list