scope

Python - How to reference a global variable from a function [duplicate]

允我心安 提交于 2019-12-10 21:14:36
问题 This question already has answers here : How can I access global variable inside class in Python (5 answers) Closed 6 years ago . I must be missing some very basic concept about Python's variable's scopes, but I couldn't figure out what. I'm writing a simple script in which I would like to access a variable that is declared outside the scope of the function : counter = 0 def howManyTimesAmICalled(): counter += 1 print(counter) howManyTimesAmICalled() Unexpectedly for me, when running I get :

AngularJS - How do I access the form defined inside a templateUrl in my directive?

大城市里の小女人 提交于 2019-12-10 20:53:00
问题 I am attempting to access the form inside my directive for validation purposes, so I'd like access to $setPristine, however, I can't seem to figure out how to get the form if it's created using a templateUrl. I have a plunker detailing the issue here: http://plnkr.co/edit/Sp53xzdTbYxL6DAue1uV?p=preview I'm getting an error: Controller 'form', required by directive 'testDirective', can't be found! Here is the relevant Plunker code: .js: var app = angular.module("myApp", []); app.directive(

What's the difference between using require in node console and use script tag in html

元气小坏坏 提交于 2019-12-10 20:42:58
问题 I'm new to the js world, this is really make me confused, yesterday I was started to cooperate underscore.js in my code, so I start to try it in REPL environment, I choose to use Node console, I came up with var _ = require (./underscore.js) , then everything works fine. Today I try to embed it in html by using <script> tag, it seems I don't need to manually var _ = underscore , object _ is already there. someone can explain why, and how to use npm to install underscore globally and require

Trying to create a scope in rails 3 for has habtm relationship

别来无恙 提交于 2019-12-10 20:38:01
问题 I'm trying to do a basic search on an active record but am having trouble because of the has_and_belongs_to_many relationship. Below are the records and scopes I've created. Class Section << ActiveRecord::Base has_and_belongs_to_many :teachers attr_accessible :department, :class_size scope :department_scope, lambda { |dept| where("department = ?", dept) } scope :teacher_fname_scope, lambda { |n| joins(:teachers) & Teacher.has_first_name(n) } end Class Teacher << ActiveRecord::Base has_and

how to create an object from a different scope

自作多情 提交于 2019-12-10 20:27:37
问题 I have an object in Guice with scope singleton. In method f() I want to create a new object but let Guice do the injection. I think it is not a good practice to pass the injector around. So how can I get a new "Guicy" instance of object? 回答1: As suggested above, probably provider is the way to do it. it is also mentioned in this question. 来源: https://stackoverflow.com/questions/9819794/how-to-create-an-object-from-a-different-scope

Extract Data from Anonymous Function Scope

旧城冷巷雨未停 提交于 2019-12-10 20:15:50
问题 Because of the complexity of this application, I have a need to wrap Facebook API calls, like so. //In main file, read is always undefined var read = fb_connect.readStream(); // In fb_wrapper.js function readStream () { var stream; FB.api('/me/feed', {limit:10000}, function (response) { stream = response.data; }); return stream; } I know that due to the asynchronous nature of the call, the rest of the readStream() function will return stream (which has no value). I am having trouble finding a

Scope of structure declared/defined within another structure

牧云@^-^@ 提交于 2019-12-10 19:51:28
问题 Reading from Nested structures, I realized that structure declared within another structure is scoped the same as the containing structure. I thought it is only scoped within the containing structure. I got this impression from this link. It says there are 4 namespaces and one of them is members of a structure. I "logically" inferred that inner structures are only scoped within the outer one. Can anyone provide a reference to the standard as to exactly how the scope rule works in this case?

Understanding bound and free variables in LISP

二次信任 提交于 2019-12-10 19:29:35
问题 I'm reading SICP , and the topic of bound and free variables has come up. However, I am confused about it. Does the term "bound variables" only apply to variables that are formal parameters? In addition, the text says that a procedure definition "binds" its formal parameters. This confuses me with the fact that some people say that we "bind" a value to a variable. Obviously, the term seems to mean different things when we're talking about different types of variables. Could someone clear up

Why can an (irrelevant) using declaration reconcile overload ambiguity with Argument-Dependent Lookup?

六眼飞鱼酱① 提交于 2019-12-10 19:07:23
问题 This is a follow up of the question here on function overload with Argument-Dependent Lookup (ADL). I wanted to check my understanding of the rules under these circumstances so I wrote some test code. First, there is no swap for HasPtr class in std, of course, so I wrote a namespace of my own which contains a HasPtr version of swap in addition to the one already defined in global scope. The using declaration works as what I expected -- an error of ambiguity was produced because there is a

do included javascript files have access to global variables in the parent document?

三世轮回 提交于 2019-12-10 18:48:46
问题 Imagine some code something like this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>BLAH</TITLE> <script language='Javascript' type='text/javascript'> var ScriptVersionReqd='1.0'; </script> <script language='JavaScript' type='text/javascript' src='clientscript.js'></script> etc. etc. Does clientscript.js have access to the variable "ScriptVersionReqd"? If not, why not? 回答1: Yes. As long as the global variable has