scope

Override list's builtins dynamically in class scope

别等时光非礼了梦想. 提交于 2019-12-11 03:49:37
问题 Purely curiosity question: class Li(list): pass m, n= Li([1]), Li([2]) def r(*args, **kwargs): raise Exception('hop') setattr(m, '__iadd__', r) m += n print m # [1, 2] setattr(Li, '__iadd__', r) m += n Output: [1, 2] Traceback (most recent call last): File "C:\...\test_override.py", line 8, in <module> m+=n File "C:\...\test_override.py", line 3, in r def r(*args, **kwargs): raise Exception('hop') Exception: hop If I use setattr(m, 'append', r) then m.append(2) will fail. So is __iadd__

How can I get session scoped bean in filter from session? (jsf 2.1)

邮差的信 提交于 2019-12-11 03:48:27
问题 How can I retrieve session scoped bean in filter? I have tried like that, but it returns null. this is my session scoped bean: @SessionScoped @ManagedBean(name="sessionData") public class SessionData { private UserWrapper userWrapper; public UserWrapper getUserWrapper() { return userWrapper; } public void setUserWrapper(UserWrapper userWrapper) { this.userWrapper = userWrapper; } } and this is filter: HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; HttpSession

How can I share a SESSION between multiple ColdFusion applications on the server/under the same domain?

筅森魡賤 提交于 2019-12-11 03:47:51
问题 Let's say I have a domain sub.domain.com with one login form at https://sub.domain.com/login.cfm. In the root directory, I have my Application.cfc which names the application using THIS.Name = "MyApp"; . I have several sub-directories on this website, which I want to run as separate applications, with their own Application.cfc which extends the root Application.cfc, but each has it's own name, so that I can create Application-scope variables unique to that application: For instance: sub

Setting variables inside a Bash loop

旧巷老猫 提交于 2019-12-11 03:40:10
问题 Just started learning Linux Bash Shell Programming, and I just don't know if I understood it correctly. Looking at the sample program below: #!/bin/bash n=1 sumRSS=1000 sumSZ=2000 echo Before sumRSS=$sumRSS sumSZ=$sumSZ ps -ly | while read c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 do if (( n>1 )) then echo n=$n rss=$sumRSS sz=$sumSZ ((sumRSS = sumRSS + c8)) ((sumSZ = sumSZ + c9)) fi ((n++)) done echo Sum of RSS = $sumRSS echo Sum of SZ = $sumSZ The output: Before sumRSS=1000 sumSZ=2000 n=2 rss=1000 sz

Cannot find symbol error [duplicate]

非 Y 不嫁゛ 提交于 2019-12-11 03:29:49
问题 This question already has answers here : What does a “Cannot find symbol” or “Cannot resolve symbol” error mean? (13 answers) Closed 4 years ago . Let me first apologize. I've been coding for a long time now, but I'm new to Java. I feel like this should be a simple error, but I've been working on it for a half hour to no avail: public String getHtml(HttpServletRequest request) { try { WebPageFetcher fetcher = new WebPageFetcher("http://google.com"); } catch (Exception e) { log.error(

is there a way to instantiate variables from iterated output in python?

柔情痞子 提交于 2019-12-11 03:17:04
问题 Say I have a list my_list = ['a','b','c'] and I have a set of values my_values = [1,2,3] Is there a way to iterate through my list and set the values of my_list equal to my_values for i in range(len(my_list)): ## an operation that instantiates my_list[i] as the variable a = my_values[i] ... >>> print a 1 I just want to do this without copying the text of file that holds the program to a new file, inserting the new lines as strings where they need to go in the program. I'd like to skip the

setTimeout calling function inside function - Scope-Issue

依然范特西╮ 提交于 2019-12-11 03:14:27
问题 So, the problem is that I have a function inside a function that needs to be called by setTimeout. That doesn't work however because setTimeout will assume that the function it calls has the root as its' scope. Any idea how I could solve this without changing the scope of the function? Edit: Here is what I mean: function general(){ function saysomething(){ console.log('hi there'); } setTimeout("saysomething();", 1000); } The setTimeout fails.. 回答1: function general(){ function saysomething(){

Strange Behavior on Global and Local Variable in JavaScript

徘徊边缘 提交于 2019-12-11 03:09:52
问题 I tried following code: var a = 5; function x() { console.log(a); } x(); It runs as expected and prints 5. But i changed the code so the global variable a will be overwrite as follows: var a = 5; function x() { console.log(a); var a = 1; } x(); It prints undefined. It doesn't make sense for me since the overwrite should be happened right after console.log(a). So what is the problem? 回答1: This is happening because your second a variable is being 'hoisted' to the top of the function and it

Add Ruby classes to a module when defined in separate files

£可爱£侵袭症+ 提交于 2019-12-11 03:07:10
问题 I would like to namespace my Ruby classes by putting them in a module. Indeed, this is a good idea if I decide to publish my Ruby gem so that the class names do not clash with existing classes in another gem. I know I can do the following for a class A::B : module A class B end end However, the above is quite cumbersome in that I need to put all my class definitions into a single Ruby source file in order to scope them under the module. I would rather keep my class definitions in separate

Javascript function call across HTML windows

久未见 提交于 2019-12-11 02:56:28
问题 According to this page I should be able to call parameters and functions of child windows, but it is not working for me. var w = window.open("index.html"); console.log(w); console.log(w.foo); console.log(w) shows that there is a function named foo but console.log(w.foo) outputs undefined . Is this a security issue? EDIT Here is some more functionality: child.html (omitting the body): <head> <script type="text/javascript"> test = 123 ; function foo(arg){ //do something } </script> </head>