Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 3
    Is this actually recommended or should it be avoided? Commented Jan 13, 2017 at 14:36
  • 3
    @Ev.Kounis: it is not considered very elegantly since one might forget that there is a variable defined outside the scope and introduce an a in a function. So one better uses object oriented programming. Commented Jan 13, 2017 at 14:37
  • 2
    @Ev.Kounis : it should definitly be avoided, unless 'a' is a constant (not supposed to change during the whole process life) - and even then it would still be better to explicitely pass a (if you care about testability that is). Commented Jan 13, 2017 at 14:47
  • I'm not saying this is this answer is the way to go. I was simply trying to point out to the OP that passing a as an argument is useless here. But defining globals is in general not a good idea. Commented Jan 13, 2017 at 14:48
  • Note that you sometimes don't have a choice. For instance tkinter callbacks often only take one or zero arguments, so you can't pass application state. So the application state has to be in the global scope for callbacks to use it. Note that OOP doesn't really help here. The common pattern of writing a UI class in tkinter often puts the whole program state in that class of which one instance is created. Which basically comes down to the same thing. Commented Jan 30, 2022 at 9:23