scope

Reason for unintuitive UnboundLocalError behaviour 2

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 14:59:59
问题 Following up on Reason for unintuitive UnboundLocalError behaviour (I will assume you've read it). Consider the following Python script: def f(): # a+=1 # 1 aa=a aa+=1 # b+='b' # 2 bb=b bb+='b' c[0]+='c' # 3 c.append('c') cc=c cc.append('c') d['d']=5 # Update 1 d['dd']=6 # Update 1 dd=d # Update 1 dd['ddd']=7 # Update 1 e.add('e') # Update 2 ee=e # Update 2 ee.add('e') # Update 2 a=1 b='b' c=['c'] d={'d':4} # Update 1 e=set(['e']) # Update 2 f() print a print b print c print d # Update 1

Ninject: give the parent instance to a child being resolved

旧城冷巷雨未停 提交于 2019-12-23 13:03:21
问题 I have this class hierarchy: public interface ISR { } public interface ICU { } public interface IFI { } public class CU : ICU { } public class SR : ISR { public SR(IFI fi) { FI = fi; } public IFI FI { get; set; } } public class FI : IFI { public FI(ISR sr, ICU cu) { SR = sr; CU = cu; } public ISR SR { get; set; } public ICU CU { get; set; } } public class Module : NinjectModule { public override void Load() { Bind<ISR>().To<SR>(); Bind<ICU>().To<CU>(); Bind<IFI>().To<FI>(); } } class Program

What kind of localization does occur in a “foreach” loop?

让人想犯罪 __ 提交于 2019-12-23 12:33:18
问题 From perldoc perlsyn on the topic of Foreach Loops: If the variable was previously declared with my, it uses that variable instead of the global one, but it's still localized to the loop. But consider this example: use Devel::Peek; my $x = 1; Dump $x; for $x ( 1 ) { Dump $x } SV = IV(0x8117990) at 0x8100bd4 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 1 SV = IV(0x8117988) at 0x8100bf8 REFCNT = 2 FLAGS = (IOK,READONLY,pIOK) IV = 1 It seems like these are not the same variables. Is it an

Using a dictionary object in application scope in Classic ASP

邮差的信 提交于 2019-12-23 12:28:57
问题 Following up from my last question does anyone know how I can use a dictionary object in application scope in Classic ASP? You cannot use Scripting.Dictionary - if you try you will see something similar to the following: Application object error 'ASP 0197 : 80004005' Disallowed object use /xxx.asp, line 2. Cannot add object with apartment model behavior to the application intrinsic object. I found this article on (good ol') 4GuysFromRolla but it points to Microsoft's free Lookup Component and

byte and ambiguous symbol due to using declarations?

佐手、 提交于 2019-12-23 12:25:50
问题 We are a C++ library . For years we had typedef unsigned char byte; in the global namespace. User programs and other libraries provided compatible definitions of byte , so there were no problems. C++17 added std::byte and changed semantics of a byte. Now we need to be more hygienic by avoid global namespace pollution; and we need to insulate ourselves from std::byte . Our change is to move our byte into our namespace. We are witnessing an unexpected failure as we test the impact of changes.

Using matlabs save in functions

北城余情 提交于 2019-12-23 12:17:44
问题 Is it possible to use the Matlab save command inside a function to store workspace variables? Consider following scenario: I've got a bunch of variables in the Matlab workspace and want all that are beginning with "a" and "b" in a .mat file. Of course this works: save('test.mat','a*','b*') but i want to have a variable filename. The function i wrote: function save_with_name(name) save(name,'a*','b*') does not work, because save_with_name doesn't see the workspace variables. Is there a

Lambda function and variable scope

此生再无相见时 提交于 2019-12-23 12:13:17
问题 Currently, my code is like this: for control in self.controls(): self.connect(control, SIGNAL('clicked()'), lambda: self.button(control.objectName())) When I run my code, my lambda function takes control to be the last element in my list of elements, which is not what I expect to happen. Oddly enough, when I manually run the lambda every loop, it works fine for each loop, but it still has the same problem as before in the end: for control in self.controls(): func = lambda: self.button(control

Request or Session scope in Spring Websocket

℡╲_俬逩灬. 提交于 2019-12-23 12:13:08
问题 From WebSocket Endpoint I try to call Singleton Service. But I an unable to use Request or Session scope from WebSocket. (@Scope( value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)) I get Scope 'request' is not active for the current thread; For 'request' or 'session' scope on any 'ScopedProxyMode'. Thanks for the help! 回答1: For web sockets there are no request/response so the request scope is invalid. They introduced new scope called websocket in Spring 4.1. @Scope(name =

What is the idea behind using a stack for local variables?

流过昼夜 提交于 2019-12-23 11:59:07
问题 In C as many of you know, the stack is where all local variables reside. The stack being a first in last out data structure means you can only access what has been most recently pushed onto it. So given the following code: int k = 5; int j = 3; short int i; if (k > j) i = 1; Obviously this is useless code which has no real meaning but I'm trying to wrap my head around something. For the short int i declaration I'm assuming 2 bytes get allocated on the stack. For int k and int j for both 4

Should I declare variables as close as possible to the scope where they will be used?

喜夏-厌秋 提交于 2019-12-23 10:19:26
问题 ReSharper usually suggests me that, and I'm still looking for a good reason of why to do that. The only thing that came to my mind is that declaring it closer to the scope it will be used, can avoid initializing it in some cases where it isn't necessary (because a condition, etc.) Something related with that is the following: int temp; foreach (var x in collection) { temp = x.GetValue(); //Do something with temp } Is that really different than foreach (var x in collection) { int temp = x