Questions tagged [globals]

Refers to a spaces where variables and other items may be accessed from any scope.

335 questions
-1
votes
2 answers

What are the alternatives to Globals in Python using Tkinter

I am teaching a class and have been told to avoid global statements using Python and Tkinter. I don't want to teach Classes to my students yet I know I can create all my entry boxes and labels out of a subroutine and my code will work, but this is…
-1
votes
1 answer

How do you set the (attribute, value) in globals() to be that of a method (name, value)?

In JS, you can do something similar, assign all key, values of an object / dict, obj to be in the global namespace / context obj with this[key] = obj[key] I expected to be able to do the same with class A: def call(self): print('a') a =…
James T.
  • 644
  • 8
  • 18
-1
votes
1 answer

Maya Python: Something is not defined (Building Generator)

I'm new to this site, and new to programming in general. I've been working on a procedural building generator in Maya2018 using Python as my language (Pycharm as my script editor). I'm getting an error saying this: "Error: Global name…
Max L.
  • 1
-1
votes
3 answers

How to use GLOBALS in php to post form data

How do I import GLOBALS variable in the main PHP file so I do not have to change project name every time in the src?
hal9000
  • 189
  • 1
  • 20
-1
votes
1 answer

PHP Why is my globals array empty in my extended class

I am having trouble getting a global array in my extended class. The array is populated by paramaters that are passed using the url. I get my url then explode it. Then I set the first two parameters to a class and method. Then re-base my array keys…
badsyntax
  • 199
  • 1
  • 14
-1
votes
1 answer

PHP setting $GLOBALS produces blank result

Is there a problem setting a global variable ? This is INSIDE a function, & in a foreach loop. These three lines are one after the other (it does not go anywhere else)... $GLOBALS["nameaa"]=$abl; $search_array_log.= " ADDING GLOBALS NAME -…
G Stewpot
  • 101
  • 1
  • 2
  • 10
-1
votes
1 answer

PHP access variable declared in function outside

i am new in PHP and i had a question: how can i access a variable declared in a function from global scope? function test(){ $x = 6; $y = 5; return $x; } test(); echo $GLOBALS['y']; I want to access variable y in global. Thank you!
-1
votes
4 answers

Switch Statement in C# Class

I have a csharp app with a xml config file containing an element called "environment" which can be set to different values (development/test/production for example). When this config file entry is modified the resulting global variables within the…
Brad
  • 1,431
  • 5
  • 25
  • 42
-1
votes
2 answers

How do I rewrite this code to avoid using the global?

I am writing some routines that directly interface with our design group's hardware. I'll try to explain this scenario as succinctly as possible. Our hardware generates various types of interrupts to the embedded CPU that runs the firmware I am…
Axel Aguado
  • 75
  • 1
  • 6
-2
votes
2 answers

Notice: Undefined variable: username

My question = Why is there no value assigned to my $username when I try to use it in editor.php? I have a log in system that works. Once the user logs in, I want to create a welcome line that says "Welcome [INSERT USERNAME HERE]". Currently, I am…
Kent Godfrey
  • 73
  • 1
  • 3
  • 10
-2
votes
1 answer

Use a variable to call a global list in python?

I want to use a variable to call a global list with the same name. So, for example: x = [1,2,3,4] y = [2,3,4,5] def function(i): return i function(x) expected output -> [1,2,3,4]
V__M
  • 23
  • 4
-2
votes
1 answer

Why parameters are passed outside the parenthesis () in globals(), locals() and vars() in Python?

I'm very new in Py but I know the syntax function(param1,.. paramN) and I can't understand this: globals()['z'] = 8 Could not be more 'standar' ? globals('z') = 8 # or.. globals(param = 'z') = 8 EDIT: thanks to all for yours answers, I just have…
boctulus
  • 332
  • 7
  • 13
-2
votes
2 answers

game errors, not sure what I am supposed to do

I have an issue with a program i am working on. It is intended to be a city simulator. The first 2 lines work, but then it does not work. The code is below. I have no idea what I am doing wrong. >>> ================================ RESTART…
-3
votes
2 answers

How to avoid global variables in this case?

I have this simple code, I want value of 'a' to be 4 at the end. 'global a' can solve it, but is there any other way? Since it's everywhere that overuse of globals is a symptom of poor design. a=3 def function(): a = 4 function() print(a)
barry23
  • 9
  • 2
-3
votes
1 answer

Can you modify variable before declaring it?

I have hundreds of variables (here is only few of them so you'll get idea how this code works) and I have no idea how to solve this problem. What I want to do is in second if statement to somehow modify variable before declaring it so I could copy…
Gunnm
  • 842
  • 8
  • 17
1 2 3
22
23