Questions tagged [globals]

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

335 questions
4
votes
1 answer

Listing all top level global variables in emacs

Mostly for my own edification I'm trying to list all of the global variables loaded in the current Emacs session. What I was thinking about doing is producing an HTML file with all of the functions listed. Of course, what would also be useful is…
lucidquiet
  • 5,441
  • 7
  • 37
  • 76
4
votes
1 answer

python globals dictionary

I want to merge a dictionary , recieved from another module as a function argument to the globals dictionary of the current module. Any idea how this can be done ? module - test.py def setdict(indict): somedict = dict(globals(), **indict) what…
Abhaya
  • 187
  • 2
  • 8
4
votes
2 answers

capture change of global variable value in python

How do i detect or capture change of value of a global variable in python variable = 10 print(variable) variable = 20 # Detect changes to the value using a signal to trigger a function UPDATE AST docs - GOOD INTRO…
Gary
  • 2,027
  • 2
  • 21
  • 42
4
votes
1 answer

How to make global variables work in Spyder inside a function?

I cannot modify global variables interactively in Spyder 4.0.0 with Python 3.8, Windows 10. There must have been a recent change because this was possible before. I have the following example file: x = 5 def IncreaseX(): global x x +=…
Dollarius
  • 51
  • 3
4
votes
2 answers

How to avoid using global in C to detect setting of variable?

I have function foo() which is called from two different code flows. Lets say these two code flows have two different functions calling foo() bar() and tar() I want to do make some decision on the basis of which function(bar() or tar()) has called…
Deeps
  • 43
  • 5
4
votes
5 answers

How to avoid globals in C?

as a beginner I read everywhere to avoid excess use of global variables. Well how to do so? My low skill fails. I am ending up passing tons of structures and it is harder to read than using globals. Argh my code is mess any good book/article…
4
votes
1 answer

Is this __import__ functionality correct?

I have a package named jiva_tasks, which I'm trying to import via celery (using the CELERY_IMPORTS attribute of celeryconfig. The import statement that celery is using is this: __import__(module, [], [], ['']) Oddly enough, when this syntax is…
Jason Baker
  • 171,942
  • 122
  • 354
  • 501
4
votes
2 answers

Scope inside Python exec

When a variable/function is defined inside an exec it seems to go to the locals() instead to the globals() how I can change this behaviour? This only happens when you pass the global and local dictionaries to the exec. Example: exec(""" a = 2 def…
3
votes
2 answers

How to avoid globals in Perl Tk (Tkx) GUI programming using an MVC model

I have an old and very large Perl Tk GUI application that I'm refactoring to Tkx. I want to split the interface into several packages so I can build up the application UI in a modular manner. Also, I want to keep the View separate from the Model,…
Lozzer
  • 753
  • 6
  • 21
3
votes
3 answers

Javascript Object Question

I'm a beginner w/ Javascript. I'm looking at the following code that someone else wrote: function MeetingPage() { MeetingPage.colors = new Object(); } ... var meeting = new MeetingPage(); From what I've seen, I believe that the MeetingPage…
mj_
  • 5,781
  • 5
  • 33
  • 69
3
votes
1 answer

Python3 globals() and locals() contents

In my Python3 learning, while trying out globals() and locals(), I made a very basic, stand-alone Python program and received results for which I ask for expert explanation. I then executed the same 2 functions inside my Python program (any) and…
samtal
  • 109
  • 1
  • 10
3
votes
1 answer

When you declare a variable of the same name both inside and outside the class/function, how do you know which value of the variable will be used?

a=0 b=1 class A: a=42 b=list((a,a+1,a+2)) x=A() print(x.b) output: [42, 43, 44] VS a=0 b=1 class A: a=42 b=list((a+i for i in range(3))) x=A() print(x.b) output: [0, 1, 2] So in the first example, a=42 was used. But in the second…
Qingwan Kuah
  • 131
  • 4
3
votes
6 answers

(php) Better way to use global variables? Or how to avoid them?

I was reading somewhere that using global variables is generally a bad idea but I am not sure what the alternative is... I have this code now and I need to use global $config, $db in every single function. = copy & paste class Layout { public…
Martin Zeltin
  • 622
  • 4
  • 16
3
votes
2 answers

Is there any point in globals or 'evil' singletons

I previously used Singletons for global classes, if it's absolutely necessary i.e. logging, error handling. But I am now using unit testing which doesn't like these! I would like to ask a basic question on globals. What's the point in them? …
Christopher Grigg
  • 1,895
  • 20
  • 28
3
votes
2 answers

Python - How to obtain a dictionary(or even a list) of variables in a specific scope; more specific than locals/globals()

So, the title pretty much says it all. for instance let's look at the below example code: ## How can I obtain a dict/list (like locals()) of all the variables in second and/or third layer scopes via a command # coming from the first layer? ## Or…
Michael Beyer
  • 79
  • 1
  • 10
1 2
3
22 23