scope

In Python 2, how do I write to variable in the parent scope?

不羁的心 提交于 2019-12-17 17:33:22
问题 I have the following code inside a function: stored_blocks = {} def replace_blocks(m): block = m.group(0) block_hash = sha1(block) stored_blocks[block_hash] = block return '{{{%s}}}' % block_hash num_converted = 0 def convert_variables(m): name = m.group(1) num_converted += 1 return '<%%= %s %%>' % name fixed = MATCH_DECLARE_NEW.sub('', template) fixed = MATCH_PYTHON_BLOCK.sub(replace_blocks, fixed) fixed = MATCH_FORMAT.sub(convert_variables, fixed) Adding elements to stored_blocks works fine

Declaring an enum within a class

六月ゝ 毕业季﹏ 提交于 2019-12-17 17:23:53
问题 In the following code snippet, the Color enum is declared within the Car class in order to limit the scope of the enum and to try not to "pollute" the global namespace. class Car { public: enum Color { RED, BLUE, WHITE }; void SetColor( Car::Color color ) { _color = color; } Car::Color GetColor() const { return _color; } private: Car::Color _color; }; (1) Is this a good way to limit the scope of the Color enum? Or, should I declare it outside of the Car class, but possibly within its own

Is the following JavaScript construct called a Closure? [duplicate]

丶灬走出姿态 提交于 2019-12-17 16:53:36
问题 This question already has answers here : What is this practice called in JavaScript? (8 answers) Closed 5 years ago . (function() { //do stuff })(); EDIT: I originally thought this construct was called a closure - not that the effect that it caused results (potentially) in a closure - if variables are captured. This is in no way to do with the behaviour of closures themselves - this I understand fully and was not what was being asked. 回答1: It is an anonymous function (or more accurately a

Is the following JavaScript construct called a Closure? [duplicate]

落爺英雄遲暮 提交于 2019-12-17 16:53:22
问题 This question already has answers here : What is this practice called in JavaScript? (8 answers) Closed 5 years ago . (function() { //do stuff })(); EDIT: I originally thought this construct was called a closure - not that the effect that it caused results (potentially) in a closure - if variables are captured. This is in no way to do with the behaviour of closures themselves - this I understand fully and was not what was being asked. 回答1: It is an anonymous function (or more accurately a

Changing array in method changes array outside [duplicate]

家住魔仙堡 提交于 2019-12-17 16:33:49
问题 This question already has answers here : Is Java “pass-by-reference” or “pass-by-value”? (86 answers) Are arrays passed by value or passed by reference in Java? [duplicate] (7 answers) Closed 5 years ago . I have trouble with scope of variable. public static void main(String[] args){ int[] test={1,2,3}; test(test); System.out.println(test[0]+" "+test[1]+" "+test[2]); } static void test(int[] test){ test[0]=5; } I expected the output to 1 2 3 , but the result was 5 2 3 . Why I changed the

Scope of variables in Julia

廉价感情. 提交于 2019-12-17 16:26:24
问题 When I ran the Julia code below, there was an error: UndefVarError: globalValue not defined . I thought that the globalValue is a global variable, but it is not. Thus, if I add the command "global globalValue" inside the for loop, my code will work. So, could anyone please have a look at it let me know what happened? Thanks in advance! globalValue = 1.0; tempValue = 0.1; for ii = 1:10 # global globalValue; if I add this command, my code will work tempValue = 5.0; ## I have a function to

I can't reach any class member from a nested class in Kotlin

ぃ、小莉子 提交于 2019-12-17 16:24:50
问题 I want to access a member of the MainFragment class from PersonAdapter class but none of them are available. I tried making both the classes and the members public and private also but so far nothing worked. I guess I'm missing something obvious but I just can't figure it out. class MainFragment : Fragment() { lateinit var personAdapter: PersonAdapter lateinit var personListener: OnPersonSelected private var realm: Realm by Delegates.notNull() lateinit var realmListener: RealmChangeListener

In ECMAScript5, what's the scope of “use strict”?

…衆ロ難τιáo~ 提交于 2019-12-17 15:46:52
问题 What scope does the strict mode pragma have in ECMAScript5? "use strict"; I'd like to do this (mainly because JSLint doesn't complain about it): "use strict"; (function () { // my stuff here... }()); But I'm not sure if that would break other code or not. I know that I can do this, which will scope the pragma to the function... (function () { "use strict"; // my stuff here... }()); but JSLint complains about it (when the "strict" JSLint option is enabled) because it thinks you're executing

When to use Spring prototype scope?

好久不见. 提交于 2019-12-17 15:42:22
问题 I want to know when should i exactly use the prototype scope in Spring? I have understood that singleton returns the same object instance if the bean is requested for. Then why should we consider prototype ? Explanations with examples would help a lot to understand the need for it. 回答1: To be clear simple definitions: Prototype scope = A new object is created each time it is injected/looked up. It will use new SomeBean() each time. Singleton scope = The same object is returned each time it is

iOS Name of this way of building and returning an object in Objective-C

北城余情 提交于 2019-12-17 14:56:08
问题 I'm trying to find out what this style of coding is called, is it an inline block? inline scope? what? What will the compiler create when it comes across one of these... - (UIView *)createMyView { return ({ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 0)]; /* set some stuff up on the view;
 */ view;
 }); } I'm asking because we're getting a lot of cxx_destruct calls in a crash log with lines numbers that are way bigger than the actual size of the file. I'm wondering if