A tag for questions about accessing resources local to a given runtime environment or network.
Questions tagged [locals]
96 questions
5
votes
2 answers
Retrieve locals() in order of variable declaration - python
For example,
a = 1
b = 2
c = 3
When call locals(), I get
{ 'a': 1, 'c': 3, 'b': 2, '__builtins__': , '__package__': None, '__name__': '__main__', '__doc__': None }
How can I retrieve local variables from…

vivify
- 53
- 2
4
votes
2 answers
Inconsistency in abbreviated month names in non-english (danish & norwegian)
I wish convert some dates in Norwegian to actual dates in R. I'm using readr, and it kind of works - but I stumbled upon an issue which really annoys me, and I don't really know how to get around it.
Here is an illustration of my problem:
>…

Kira
- 85
- 1
- 9
4
votes
1 answer
Confusion with debug.getlocal in Lua
I saw here how to insert local variables in a table using the debug.getlocal function in Lua (5.1).
function locals()
local variables = {}
local idx = 1
while true do
local ln, lv = debug.getlocal(2, idx)
if ln ~= nil then
…

yawn
- 422
- 1
- 5
- 21
4
votes
1 answer
How can I force update the Python locals() dictionary of a different stack frame?
In Python 2 (not sure about 3), the locals dictionary only gets updated when you actually call locals(). So e.g.
l=locals()
x=2
l['x']
fails because l doesn't have the key "x" in it, but
l=locals()
x=2
locals()
l['x']
returns 2.
I'm looking for a…

marius
- 1,352
- 1
- 13
- 29
4
votes
1 answer
Cannot send variable to partial using Cocoon (Rails 3)
i'm using Rails 3, with standard rails form and Cocoon gem. I want to send a variable to a partial through the 'link_to_add_association' using the 'render_options' provided by the gem, but i cannot make it work. The view from the partial is…

gonzag88
- 101
- 1
- 8
4
votes
1 answer
Compilation implications of declaring all scope locals in the beginning as in early C?
I remember hearing that lining up all scope members in the beginning of the block was no longer recommended practice with both C and C++, but does this mean it obstructs the compiler in some way when generating code, or simply that it is no longer…
user2341104
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…

Josep Virgili Llop
- 51
- 3
4
votes
3 answers
How to dynamically modify a function's local namespace?
NB: This question assumes Python 2.7.3.
I'm looking for a sane approach to dynamically modify a function's local namespace, preferably in a way that adds the least clutter to the body function.
What I have in mind would look something like…

kjo
- 33,683
- 52
- 148
- 265
3
votes
1 answer
Customizing locals based on Devise scopes
I have a User and a Client model setup to use Devise with different sign-up workflows. I want to customize the locals based on the resource (Client or User). For example, instead of using the default devise message in config/locals/devise.en.yml for…

mbsheikh
- 2,501
- 5
- 23
- 33
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
- 261
- 2
- 6
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
- 85
- 2
- 10
3
votes
1 answer
What is the best way to turn a python dictionary into variables?
We have a config.yaml file like this:
darwin:
installer:
title: "%(product_name)s %(version)s"
filename: "%(brand_name)s-%(version)s"
and a function to format it:
def format_context(config):
return {
"company_name":…

quanta
- 3,960
- 4
- 40
- 75
3
votes
4 answers
Getting local variables of function
I'm trying to get a local variable from a decorator. An example:
def needs_privilege(privilege, project=None):
"""Check whether the logged-in user is authorised based on the
given privilege
@type privilege: Privilege object, id, or str
…

Martijn
- 586
- 5
- 19
3
votes
2 answers
Strange results in my locals window for VS2008
static void Main(string[] args)
{
List myList = new List() { "A", "B" };
string myString = "abc";
int myInt = 42;
System.Xml.Linq.XElement root = new System.Xml.Linq.XElement("abc");
…

Amy B
- 108,202
- 21
- 135
- 185
3
votes
2 answers
Can't access variable created by altering locals() inside function
I need to assign some variables when calling a funcion with the name of the variable as an argument.
Therefore, I loop through a tuple with the desired names, assigning them via the locals() dict.
It works, but then I can't access them by name -…

lembon
- 125
- 7