All Questions
1,132
questions
2
votes
1
answer
34
views
xlwings not updating global variable correctly when using threading
Here is my logic that I am trying to understand.
import xlwings as xw
import threading
workbook = ""
def function1():
t1 = threading.Thread(target=function2)
t1.start()
t1.join()...
-2
votes
0
answers
50
views
i want to acsess the global variables from a function body in python [duplicate]
I have a very long program and I want to implement a method to access the global variables present in the main program ( main.py ) from within a function called from a library ( file.py ).
main.py :
...
1
vote
1
answer
47
views
Caching previous values in solve_ivp
I want to use the temperature at the previous timestep when evaluating the next timestep. I don't want to use global, because I think it slows down the code and it is not very clean.
I use scipy....
1
vote
1
answer
38
views
using eval() inside function with input of function as part of string
I have this code:
def system(into):
global sys
x = into
sis = [eval(i) for i in sys]
return sis
if __name__ == "__main__":
sys = ['x[0]+x[1]','2*x[0]-3*x[1]']
I would ...
4
votes
2
answers
75
views
Python global variables in recursion get different result
I have this code, which prints 1:
s = 0
def dfs(n):
global s
if n > 10:
return 0
s += dfs(n + 1)
return n
dfs(0)
print(s)
If I modify dfs like this:
def dfs(n):
...
1
vote
1
answer
36
views
Global variable not being updated with a thread in python
I have a Thread that is checking every hour of a time and keep updating a global variable, for some reason global statement is not working and it's keeping the same value in the global variable even ...
0
votes
1
answer
54
views
How to get rid of a global.target within the terminal on MacOS?
I have run into this problem where anything I install with pip installs to my main location of python and not to my virtual environments.
The following line is what I get when I run: python3 -pip ...
0
votes
1
answer
60
views
Python logging global variable in an imported library
Can someone explain the behavior of logging behavior in a library which is imported? The log contains a supposedly global variable called trace_id.
I have the following library:
my_library/
__init__....
-1
votes
2
answers
73
views
how to create a Python global variable whose name is the value of another variable [duplicate]
Given...
myGlobalVariableName = "zorp"
myGlobalVariableValue = "hello"
, ...how can I use the values of myGlobalVariableName and myGlobalVariableValue to create the global ...
-1
votes
1
answer
107
views
How do you get all the classes in another package so they can be instantiated in Python3?
I read the question "Importing a whole folder of python files", but it does not include a way to do it without one import per file.
Beside the requirement of avoiding several imports, it is ...
0
votes
0
answers
17
views
In wtforms, how to use one form to set defaults for another
This is my first attempt to use WTF. I would like to collect data from one form and use it to set a default in another. I am using a global to try to do this, because I don't know another way. Here is ...
0
votes
0
answers
47
views
when importing a function in a different file, the function produces less output
In one file (function_general) I created an function called process_excel.
This has as input an Excel file path and a list of dictionaries.
As output I have dataframes, the same amount of the length ...
1
vote
1
answer
53
views
How to define globals for this timeit call?
This Python 3.11 script benchmarks function f:
import numpy as np, timeit as ti
def f(a):
return np.median(a)
a = np.random.rand(10_000)
m = None
fun = f'm = f(a)'
t = 1000 * np.array(ti.repeat(...
0
votes
1
answer
93
views
Python not using global variable in function even when global command is used
I am trying to change the value of a global variable in a function, however this is not happening even when "global" is specified before attempting to use/alter the variable.
Here is an ...
0
votes
0
answers
31
views
How am I able to change tkinter widgets variable inside a function without the global keyword? [duplicate]
import tkinter
def why():
global label_text
label_text = ("How I am able to access 'label' and 'root' which are global variables, without global keyword?\n"
"...