Skip to main content
4042 votes
27 answers
4.3m views

How do I create or use a global variable inside a function? How do I use a global variable that was defined in one function inside other functions? Failing to use the global keyword where appropriate ...
user46646's user avatar
  • 160k
1280 votes
19 answers
1.0m views

I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables across source ...
user avatar
697 votes
13 answers
926k views

I have a global variable in JavaScript (actually a window property, but I don't think it matters) which was already populated by a previous script, but I don't want another script that will run later ...
Guss's user avatar
  • 32.8k
608 votes
17 answers
313k views

I am creating an application which requires login. I created the main and the login activity. In the main activity onCreate method I added the following condition: public void onCreate(Bundle ...
Niko Gamulin's user avatar
  • 66.6k
457 votes
6 answers
63k views

Working on an idea for a simple HTMLElement wrapper I stumbled upon the following for Internet Explorer and Chrome: For a given HTMLElement with an id in the DOM tree, it is possible to retrieve the &...
KooiInc's user avatar
  • 124k
456 votes
4 answers
479k views

How can I print all global variables/local variables? Is that possible in gdb?
cpuer's user avatar
  • 7,923
377 votes
6 answers
885k views

I know I should avoid using global variables in the first place due to confusion like this, but if I were to use them, is the following a valid way to go about using them? (I am trying to call the ...
Akshat Shekhar's user avatar
360 votes
11 answers
453k views

From my understanding, Python has a separate namespace for functions, so if I want to use a global variable in a function, I should probably use global. However, I was able to access a global variable ...
nik's user avatar
  • 8,825
358 votes
12 answers
476k views

I have a problem where i'm initialising a variable on the scope in a controller. Then it gets changed in another controller when a user logs in. This variable is used to control things such as the ...
Lightbulb1's user avatar
  • 12.9k
329 votes
14 answers
447k views

How can I create global variable keep remain values around the life cycle of the application regardless which activity running.
d-man's user avatar
  • 58.2k
317 votes
15 answers
120k views

When I try this code: a, b, c = (1, 2, 3) def test(): print(a) print(b) print(c) c += 1 test() I get an error from the print(c) line that says: UnboundLocalError: local variable 'c' ...
tba's user avatar
  • 6,651
313 votes
28 answers
188k views

In C/C++, there is a widespread opinion that global variables are "bad" and should be avoided when possible. Leaving aside the question whether this opinion is correct or not, what are the ...
user avatar
235 votes
10 answers
251k views

I know that in general, global-variables are to be avoided. Nevertheless, I think in a practical sense, it is sometimes desirable (in situations where the variable is integral to the program) to use ...
Brian Oh's user avatar
  • 10.9k
230 votes
8 answers
333k views

What am I doing wrong here? counter = 0 def increment(): counter += 1 increment() The above code throws an UnboundLocalError.
Randomblue's user avatar
  • 117k
212 votes
17 answers
428k views

It seems that I may have inadvertently loaded the password validation plugin in MySQL 5.7. This plugin seems to force all passwords to comply to certain rules. I would like to turn this off. I've ...
Alex Ryan's user avatar
  • 3,829

15 30 50 per page
1
2 3 4 5
592