Questions tagged [locals]

A tag for questions about accessing resources local to a given runtime environment or network.

96 questions
101
votes
8 answers

Python: load variables in a dict into namespace

I want to use a bunch of local variables defined in a function, outside of the function. So I am passing x=locals() in the return value. How can I load all the variables defined in that dictionary into the namespace outside the function, so that…
D R
  • 21,936
  • 38
  • 112
  • 149
57
votes
3 answers

Using locals() and format() method for strings: are there any caveats?

Are there any disadvantages, caveats or bad practice warnings about using the following pattern? def buildString(user, name = 'john', age=22): userId = user.getUserId() return "Name: {name}, age: {age}, userid:{userId}".format(**locals()) I…
Rafael S. Calsaverini
  • 13,582
  • 19
  • 75
  • 132
26
votes
5 answers

Rails 3, passing local variable to partial

Possible Duplicate: Rails: confused about syntax for passing locals to partials I want to pass local variable(which doesn't have relevant field in model) to partial. # infos/index.html.erb <%= render :partial => 'info', :locals => {:info =>…
nothing-special-here
  • 11,230
  • 13
  • 64
  • 94
20
votes
4 answers

Visual Studio 2010 Locals Window Red Font

One of my Debug.Assert() fails so I get a window with the call stack and I click Retry. At this point, in the Locals window, certain rows have red text instead of black text in the Value column. What does this mean?
bouvierr
  • 3,563
  • 3
  • 27
  • 32
14
votes
1 answer

Why does locals() return a strange self referential list?

So I'm using locals() to grab some arguments in the function. Works nicely: def my_function(a, b): print locals().values() >>> my_function(1,2) [1, 2] Standard stuff. But now let's introduce a list comprehension: def my_function(a, b): …
12
votes
1 answer

Python scoping in dict comprehension

>>> x = 'foo' >>> {0: locals().get('x')} {0: 'foo'} >>> {0: locals().get('x' + spam) for spam in ['']} {0: None} What is the reason for this discrepancy in behaviour?
wim
  • 338,267
  • 99
  • 616
  • 750
11
votes
5 answers

Why is it bad idea to modify locals in python?

Related to this reply here. Locals' doc here. The docs mention that the dictionary should not change, not sure what it means but would locals() be applicable in lab-reports where data won't change, for example in measurements?
hhh
  • 50,788
  • 62
  • 179
  • 282
11
votes
3 answers

Python locals() for containing scope

TL;DR: I want a locals() that looks in a containing scope. Hi, all. I'm teaching a course on Python programming to some chemist friends, and I want to be sure I really understand scope. Consider: def a(): x = 1 def b(): …
mmtrebuchet
  • 165
  • 2
  • 7
11
votes
2 answers

Getting local variables from a stack frame on the JVM

Is there any way to get a map or other data structure of the local variables in the current scope in on the JVM without using a debugger? That is, to get the locals of the current stack frame? I know that there are stacktrace objects, but…
bobpoekert
  • 934
  • 1
  • 11
  • 26
10
votes
3 answers

rails fields_for render partial with multiple locals producing undefined variable

All, I am experiencing a problem with a standard fields_for setup. In my "_form" partial I have:
<%= f.fields_for :comments do |cf| %> <%= render :partial => 'comments/comment_fields', :locals => {:f => cf, :tester…
astjohn
  • 2,922
  • 1
  • 22
  • 25
10
votes
2 answers

Search Value in VS2010 Debug Locals and/or expand all Nodes

does someone might know how to search for a value in the locals in visual studio 2010 or at least how can I expand all nodes, subnodes?
csharpnoob
  • 505
  • 1
  • 9
  • 24
10
votes
2 answers

ExpressJS: What is the difference between app.local and res.local?

I'm trying to learn Express and in my app I have middleware that passes the session object from the Request object to my Response object so that I can access it in my views: app.use((req, res, next) -> res.locals.session = req.session …
aeyang
  • 807
  • 4
  • 9
  • 18
7
votes
4 answers

Calling locals() in a function not intuitive?

This may be elementary, but may help me understand namespaces. A good explanation might step through what happens when the function definition is executed, and then what happens later when the function object is executed. Recursion may be…
tfj
  • 87
  • 1
  • 7
6
votes
2 answers

Python - locals() and closure

I can not find an adequate explanation for this behavior. >>> def a(): ... foo = 0 ... print locals() ... def b(): ... print locals() ... b() >>> a() {'foo': 0} {} But: >>> def a(): ... foo = 0 ... print…
5
votes
1 answer

Pug/Jade get all variables in a given template

For a given Jade/Pug template I would like to get a list of all variables which occur within the template. My motivation is as follows: In my software, different templates are used to generate some HTML snippets. Based on a given context (i.e.…
qqilihq
  • 10,794
  • 7
  • 48
  • 89
1
2 3 4 5 6 7