parameter-passing

How to pass a class variable as a default value in a static method in Python

吃可爱长大的小学妹 提交于 2019-12-02 04:54:01
问题 I want to pass a class variable as a default value to a static method. But when I import the class I get an error NameError: name 'MyClass' is not defined class MyClass: x = 100 y = 200 @staticmethod def foo(x = MyClass.x, y = MyClass.y): return x*y 回答1: MyClass is not defined yet when Python wants to bind the default arguments, but x and y are already defined in the classes' scope. In other words, you can write: class MyClass: x = 100 y = 200 @staticmethod def foo(x=x, y=y): return x*y Note

Choose AS400 query records directly from Excel

不想你离开。 提交于 2019-12-02 04:50:41
I've been searching the internet for hours trying to figure out if the following is even possible: To choose the AS400 query records directly from Excel. I haven't found any solution or description of how this could be achieved, which makes me guess that it's simply not possible. However, I haven't seen anyone confirm that it is impossible. So my question is: Is this possible? And if it is, could you point me in the right direction in order for me to start learning how to do it? I know its possible to run a query from Excel, and then adding parameters via SQL statements, but in my case, this

Push doesn't modify the list being a function argument

独自空忆成欢 提交于 2019-12-02 04:46:18
问题 I'm new to common lisp, so hope someone would clarify this to me: say we have a list and want to add an item with push to modify it: CL-USER> (defparameter xx '(1 2 3)) XX CL-USER> xx (1 2 3) CL-USER> (push 100 xx) (100 1 2 3) CL-USER> xx (100 1 2 3) as expected. But when i try to do the same with the function, it doesn't modify a list: CL-USER> (defun push-200 (my-list) (push 200 my-list)) PUSH-200 CL-USER> (push-200 xx) (200 100 1 2 3) CL-USER> xx (100 1 2 3) so i tried to compare argument

How do I use arguments of a function when using sapply?

三世轮回 提交于 2019-12-02 04:35:31
问题 I have a dataset which I created by column binding using the cbindX function from the gdata package. This function allows me to bind columns with different numbers of rows. So, NA 's are introduced when there are no values in a particular column. Now, I want to calculate the standard deviation for each column. I tried using sapply(dataset,sd) This returns the standard deviation for the column having all rows with values and NA for the columns having fewer rows. I tried using the na.rm

Event listener firing too early when parameters are passed

陌路散爱 提交于 2019-12-02 04:05:59
I pass a number of parameter to a javascript function which builds a form for the user to fill in. Among these parameters are two more functions contained in a separate class which handle the saving or canceling of the form. The cancel function requires two parameters which it uses to determine which list of entities to build. The problem lies in the parameters. While in the form building function, if I attached the cancel function to the newly created cancel button without giving it any parameter the function button works fine but builds an empty list due to the lack of parameters. However if

What happens to a parameter passed by value that is modified locally?

我是研究僧i 提交于 2019-12-02 03:47:59
I am well aware that modifying a function's argument that is passed by value is ineffective outside of the C/C++ function, but compilers allow it - but what happens? Is a local copy made of the argument and that is modifiable within the function? #include <stdio.h> void doSomething( int x ) { x = 42; printf( "The answer to Life, the Universe and Everything is (always): %i!\n", x ); } int main( int argc, char **argv ) { int a = 0; doSomething( a ); return -a; } Now this always exits without error, but where in the scheme of things (memory space) is the value represented in the function as x

JSP: Make a reusable code (tag, macro) and use it on the same page

天涯浪子 提交于 2019-12-02 03:41:55
Is there any way to make some sort of parametrized macro on one JSP page and reuse it few times on the same page. JSP tags could be used but I would have to make one file per tag. I've been wanting this functionality for years, and after googling yet again, I wrote my own. I think tag / jsp files & custom tag classes are great, but are often overkill for simple one-offs like you describe. This is how my new "macro" tag now works (here used for simple html rendering of sortable table headers): <%@ taglib prefix="tt" uri="/WEB-INF/tld/tags.tld" %> <!-- define a macro to render a sortable header

Are functions evaluated when passed as parameters?

ぃ、小莉子 提交于 2019-12-02 03:27:48
if I have some code like this: def handler(self): self.run(self.connect) def connect(self, param): #do stuff... def run(self, connector): self.runner = connector What's evaluated first when I call self.run(self.connect)? run with the stuff in connect already done? or connect with self.connect yet to be evaluated? Passing a function as a parameter does not call it: In [105]: def f1(f): .....: print 'hi' .....: return f .....: In [106]: def f2(): .....: print 'hello' .....: In [107]: f1(f2) hi Out[107]: <function __main__.f2> of course, if you pass a function call to another function, what you

passing this as parameter in static method

送分小仙女□ 提交于 2019-12-02 03:20:42
I'm having some trouble with some code in Visual C# for Windows Phone The trouble is not that it does not work, because it does, but I don't understand how =P Within a static class, a static method is created, which gives itself as a parameter: public static void MethodONe( this Timeline animation ) { //this class does not extend the TimeLine class, and is not connected to it in any //such way. animation.MethodTwo( ); } public static void MethodTwo( this Timeline animation ) { someCode( ); } How is this parameterpassing called, and what does it do, exactly? This is a so called extention method

c function parameters order of evaluation

浪子不回头ぞ 提交于 2019-12-02 03:18:16
I understand that there are no guarantees regarding the order which the parameters of a function will be called, but, isn't it guaranteed that if there's a function call as parameter, that function will be called first? I help students on the laboratory of an introductory subject on programming, and they were supposed to create a recursive factorial function which receives the n (for n!) and a pointer to an integer that will be used to count function calls and then they are supposed to print the results (n, n! and count). Many were complaining that their use of pointers were wrong so I looked