The reason you can't access var outside the functions even though you're using the global keyword, is that the global declaration only tells python to use the global var inside the functions and not to define it in the global scope (outside the functions), which is why you get a NameError when you try to access it elsewhere.