global-variables

Import a list from parent folder

Import a list from parent folder Question: parent_folder | – folder_1 |- a.py | – folder_2 |- b.py | – C.py If I have declared a list in c.py , how can I access it in a.py & b.py. No matter what I try, I keep running into ModuleNotFoundError. C.py def my_func(): my_list = ["value_1", …

Total answers: 1

Trying to avoid Globals in Python Functions

Trying to avoid Globals in Python Functions Question: I’m still munching through learning the ins and outs of Python3 through multiple sources (books like LPTHW and online resources) and I like to mash up everything I have learned in some of the tasks… only this one has me stumped as I come from a limited …

Total answers: 1

Listening for user inputs to to manipulate functions already running

Listening for user inputs to to manipulate functions already running Question: I have 2 files, main.py and app.py main.py import _thread import time def launch(thread_name): h = Hello() h.say_hello() def input_reader(thread_name): global should_say_bye should_say_bye = False x = input() if x.lower() == "q": # Should run the say_bye() function from the Hello class. But using …

Total answers: 2

python function global and local scope confusion

python function global and local scope confusion Question: I have a code in which I declare a variable globally. Then inside a function, when I try to use it, it gives an error Unbound variable is not declared My code: count_url =1 def foo(): … ttk.Label(canvas1, text=f'{varSongTitle}…Done! {count_url}/{str(var_len)}’).pack(padx=3,pady=3) root.update() count_url = count_url + 1 When …

Total answers: 1

Adding suffix to variable for every iteration of for loop in python

Adding suffix to variable for every iteration of for loop in python Question: I have searched for similarly worded questions but haven’t found one that answers my question. I have 2 dataframes showing the results on exam_1 and exam_2: exam_1 = pd.DataFrame([[‘Jim’, 87], [‘Toby’, 44], [‘Joe’, 71], [‘Tom’, 59]], columns=[‘Name’, ‘Score’]) exam_2 = pd.DataFrame([[‘Tom’, 88], …

Total answers: 2

Iteration count in recursive function

Iteration count in recursive function Question: I am writing a recursive function to make permutations of digits from 0 to n. The program will return the th permutation that is obtained. It all works well but I had to use the cheap trick of defining count as a list, that is count=[0]. In this way …

Total answers: 2

Global variable not working NameError: name 'lives' is not defined

Global variable not working NameError: name 'lives' is not defined Question: I am new to coding and I am trying to build a simple rock-paper-scissor game. While trying to implement lives in the game I cannot seem to be able to loop while lives > 0. Although I tried to make the lives variable global …

Total answers: 2

Extracting a streaming return variable in my class

Extracting a streaming return variable in my class Question: I’m using bluepy and I have a base code to read values comming from an arduino now I have the problem that when I try to extrac the variable num or tum from def handleNotification I don’t have any succes in the code: So I want …

Total answers: 1

How to add items to a dictionary between two methods?

How to add items to a dictionary between two methods? Question: I’m writing a method that takes in a list and returns a dictionary. This method is to be saved in a separate Python file and imported into Main.py The method that takes in a list calls another method that’s meant to update the global …

Total answers: 1