If you want to assign, rather than read, a global variable from a function, you will need the global
:
def main(argv): global myGlobal
Otherwise, the assignment will simply create a new local variable that obscures your global variable (therefore, changes to it will not affect the global variable, as is the case in your example).
However, you could also use the class here so that your functions share state:
class MyApp(object): def main(self, argv): self.myVar = "bar" self.mySub() def mySub(self): print self.myVar MyApp().main(sys.argv[1:])
source share