Global Variable In Main Not Getting Recognised In Another Function In Python
Solution 1:
Writing global ui
in main
does nothing except make it so that main
itself can write to a global variable called ui
. If you want to write to that global variable from other functions (like your __init__
), you need to include a global
declaration there too. Every function where you want to assign to a global variable has to have its own global
declaration.
Solution 2:
okay, thanks to people for various suggestions that helped me learn about the global scoping. I followed the answer by Jeff Shannon here : Using global variables in a function other than the one that created them seem to be able to get rid of the name scoping error caused by using global ui. here is what i did i used ui=urwid.raw_display.Screen() right after the imports and then declared global ui in the functions that used it. But now I get a different kind of error. Think it best to start a new question with the error now obtained.
Post a Comment for "Global Variable In Main Not Getting Recognised In Another Function In Python"