Skip to main content

All Questions

Tagged with
-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 : ...
Zaky202's user avatar
  • 15
-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 ...
John Glen's user avatar
  • 883
1 vote
1 answer
159 views

Python global variable on __main__

since multiprocessing need to be put inside __main__ in windows, i found out that my global variable is not passed to my function. from multiprocessing import Pool, Value def Proses(lines): ...
J. Doe's user avatar
  • 25
-4 votes
1 answer
27 views

Best practice for using Returned Value on Function Call

Made a basic Python for my utility and it was the first project I made learning how to code, I know it's messy, that's why I am here. In this program, the button below "Upload XML File" ...
phaynes's user avatar
  • 15
2 votes
1 answer
142 views

Creating copy of globals()

In python, I'm trying to write a utility function to time how long functions take to run. It's basically a helper function that makes working with timeit easier. Here's my code. If any of it seems ...
Zach Joseph's user avatar
0 votes
0 answers
23 views

Why global variable is giving an error: name 'po' is not defined. Did you mean: [duplicate]

I am a python newbie, so question could be so simple sorry for that already. class Solution: po = 0 def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]: ...
Arman Engin Sucu's user avatar
0 votes
0 answers
19 views

Function accesses global variable depending on useage in function [duplicate]

I only just came across this and it's managed to confuse me. I tried to use the same idea as Function2 but it didn't work, what confused me was it was managing to access other global variables even ...
hjw's user avatar
  • 13
0 votes
2 answers
112 views

What am I missing for determining the winner by votes?

I'm trying to think of a way to make functions that determine the winner of an election by most votes, as well as a function that determines a winner-takes-all rule. My code is as follows: _base_dict =...
L4w1i3t's user avatar
  • 43
1 vote
1 answer
60 views

I want to import a Python3 function from a different folder with GLOBAL scope

I am working in Python3.x on Linux Mint 21 and here is my directory structure: └── main_dir/ ├── all_files_dir/ │ ├── a_files_dir/ │ │ └── file_a.py │ ├── b_files_dir/ │ │...
Pavel Bogdanov's user avatar
-2 votes
1 answer
75 views

Global Constants in Python3 [closed]

I have some code which was written in Python2.7 and I need to convert it to Python3. My problem is that I used this https://code.activestate.com/recipes/65207-constants-in-python/ to create a ...
Mick Sulley's user avatar
0 votes
1 answer
136 views

Python - global variable inside a while loop

I have this code, where: last_price - is a variable that gets data from a price feed. the code, does not work as intended. it shows this output "2 test line Y", but it should show 'test line ...
Alex's user avatar
  • 3
0 votes
1 answer
243 views

How to access variables in a function, where are they stored in memory

Hey where doe Python store variables in a function and how do i access them Lets say i have the following code: import ctypes def reveal(): me = "where" print(id(me)) reveal() # ...
Alex's user avatar
  • 91
0 votes
1 answer
105 views

Tkinter global modules

Hello! I've heard that the global function can lead to problems especially when debugging, so I'd like to know if anyone has an idea how to write the following python code the best way possible. ...
user avatar
1 vote
2 answers
32 views

Can I create global variable in fuction scope in Python?

I wonder if I can create a new variable and set it as a global variable. Something like it this: def f(): global new_global_var if new_global_var is undefined: new_global_var = None ...
Jet C.'s user avatar
  • 176
0 votes
1 answer
76 views

Python global and local variable inside function

I am confused with this part of the code (what I pasted here is simplified version of the actual code). When I run the following code: def function_1(): apples = 0 apples += 1 print(apples)...
Belphegor's user avatar

15 30 50 per page
1
2 3 4 5
8