Linked Questions

4042 votes
27 answers
4.2m 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
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
-2 votes
2 answers
209 views

q=8 def example(q): global q q=q+2 print(q) example() File "<ipython-input-35-0e5cbb9ebefd>", line 2 global q ^ SyntaxError: name 'q' is parameter and global ...
Kulangara Silpa Prabhu's user avatar
-2 votes
1 answer
73 views

I want to get a directory with a function and use the obtained path in another function. For example, I'm just giving a simple code sample. def browse_folder(): input_folder = input("enter ...
Mj Sahragard's user avatar
0 votes
0 answers
63 views

I know it is a basic question but i don't know reason of this question. I am confused a bit, why global variable is act as local variable in test method. x=1 def test(): print x x=2 ...
Ashish Jain's user avatar
0 votes
0 answers
43 views

I am trying to make the worst cookie clicker game but when you click the "cookie" nothing gets added to the score. (I'm not using pygame btw) Here is the code I'm using: import tkinter from ...
User102's user avatar
  • 35
0 votes
0 answers
37 views

I'm making a program that display the location of a vehicule on a map, I use "tkintermapview" to display a map, and tkinter to display stuff on it (road it's suppose to be on, icone to show ...
Maxime's user avatar
  • 13
0 votes
0 answers
28 views

The function works by looking at the string-value of the autosave and setting it to "yes" or "no". The programm itself seems that it wont reference to the variable. from tkinter ...
B3Crazy's user avatar
  • 11
0 votes
0 answers
27 views

I'm working on something in python where I need to use a global variable that is changed by a function. However, when I try to change the value inside the function, python instead creates a new local ...
Virha's user avatar
  • 1
0 votes
0 answers
26 views

I am learning how to use signals. I created a small program that connects to a database and prints the results. I am leaving the database connection open. I am sending a SIGTERM to end the program. ...
newdeveloper's user avatar
0 votes
0 answers
26 views

I have a decorator which inits a global dict which I want to modify within the decorated function. I have tried an implementation something like below: def decorator(): def inner_function(func): ...
Tarique's user avatar
  • 711
0 votes
0 answers
18 views

I'm trying to make a function that returns whether or not a List is in descending order by using recursion, but the variable descending seems to be changing from True back to False on its own. Also, I ...
alexion's user avatar
  • 13

15 30 50 per page