of     1   

MyDominus
#183805284Wednesday, February 17, 2016 4:20 AM GMT

How would I refer to a variable that all classes share? eg: class Something(): main = 0 def AddToMain(self,num): main = main + num def PrintMain(): print(main) a = Something() b = Something() a.AddToMain(5) b.AddToMain(4) a.PrintMain() b.PrintMain() output should be 9 9
DrHaximus
#183805556Wednesday, February 17, 2016 4:25 AM GMT

def AddToMain(self,num): Something.main = Something.main + num
128Gigabytes
#183805676Wednesday, February 17, 2016 4:27 AM GMT

I have no clue if this will work because I have never used Python before but some googling looks like this might do it? global main main = 0 class Something(): def AddToMain(self,num): global main main = main + num def PrintMain(x): global main print(main) a = Something() b = Something() a.AddToMain(5) b.AddToMain(4) a.PrintMain() b.PrintMain()
DrHaximus
#183805754Wednesday, February 17, 2016 4:28 AM GMT

@128 to do static members properly, it should be done like this: class Something: main = 0 def AddToMain(self,num): Something.main = Something.main + num def PrintMain(self): print(Something.main) a = Something() b = Something() a.AddToMain(5) b.AddToMain(4) a.PrintMain() b.PrintMain() => 9 => 9
MyDominus
#183805813Wednesday, February 17, 2016 4:30 AM GMT

Thanks, both worked
128Gigabytes
#183805878Wednesday, February 17, 2016 4:31 AM GMT

Okay lol, thanks I'm not really interested in learning Python at the moment though but maybe that will help OP. I just threw his code into an online compiler and copy pasted the errors into google until the output said 9 9
spinywind
#183807222Wednesday, February 17, 2016 4:54 AM GMT

Your a quick learner... I have no idea about any other coding laguages and it would take me awhile to learn them. How.....lol

    of     1