Can some one please help me with python lists. I created a global variable and global list. Updated global values in other methods. global value updated fine, but global list gave me an error.
class Practice(object):
foo = []
var = 0;
def __updateVaribale(self):
global var
var = 9;
def __updateList(self):
global foo
foo.append("updateList 1")
def main(self):
self.__updateVaribale();
global var
print(var)
self.__updateList()
global foo
print(foo)
Obj = Practice();
Obj.main();
output
9
Traceback (most recent call last):
File "Python Test\src\Practice.py", line 31, in <module>
Obj.main();
File "Python Test\src\Practice.py", line 26, in main
self.__updateList()
File "Python Test\src\Practice.py", line 18, in __updateList
foo.append("updateList 1")
NameError: name 'foo' is not defined