argument-passing

Keyword argument in unpacking argument list/dict cases in Python

岁酱吖の 提交于 2019-11-30 05:44:58
问题 For python, I could use unpacking arguments as follows. def hello(x, *y, **z): print 'x', x print 'y', y print 'z', z hello(1, *[1,2,3], a=1,b=2,c=3) hello(1, *(1,2,3), **{'a':1,'b':2,'c':3}) x = 1 y = (1, 2, 3) z = {'a': 1, 'c': 3, 'b': 2} But, I got an error if I use keyword argument as follows. hello(x=1, *(1,2,3), **{'a':1,'b':2,'c':3}) TypeError: hello() got multiple values for keyword argument 'x' Why is this? 回答1: Regardless of the order in which they are specified, positional

Elegant way to pass multiple arguments to a function

半腔热情 提交于 2019-11-30 01:14:58
I've got a function which looks like this: bool generate_script (bool net, bool tv, bool phone, std::string clientsID, std::string password, int index, std::string number, std::string Iport, std::string sernoID, std::string VoiP_number, std::string VoiP_pass, std::string target, int slot, int port, int onu, int extra, std::string IP, std::string MAC); In my opinion it looks ugly. What is the proper way of handling this problem? Should I create few vectors with different data types (int, string and bool) and pass them as arguments to this function? If all these parameters are meaningfully

How to pass arguments to functions by the click of button in PyQt?

天涯浪子 提交于 2019-11-29 21:01:47
I want to pass the arguments to a function when I click the button. What should I add to this line button.connect(button, QtCore.SIGNAL('clicked()'), calluser(name)) so it will pass the value to the function: def calluser(name): print name def Qbutton(): button = QtGui.QPushButton("button",widget) name = "user" button.setGeometry(100,100, 60, 35) button.connect(button, QtCore.SIGNAL('clicked()'), calluser(name)) One more thing, buttons will be generated using for loop; so name value will vary. So I want to attach each name with the button. I have done same thing in Pytk by using for loop and

C++:How to pass reference-to-function into another function?

…衆ロ難τιáo~ 提交于 2019-11-29 18:21:41
问题 I have been reading about function pointers and about using them as parameters for other functions. My question is how would you pass a function by reference without using pointers? I have been trying to find the answer on the Internet but I haven't found a good answer. I know that you can pass variables by reference like this: void funct(int& anInt); . How would you do something similar to this but instead of a reference to a variable a reference to a function was the parameter? Also how

pass parameters to php with shell

限于喜欢 提交于 2019-11-29 13:47:55
my question is probably easy to answer. i want to execute my php file with shell and pass parameters to it via shell example php test.php parameter1 parameter2 is there a way to do that except using GET ? thanks AlphaMale Yes you can do it like that but you should reference the arguments from the $_SERVER['argv'] array. $_SERVER['argc'] will tell you how many args were received, should you want to use that as a first layer of validation to make sure a required number of args were input. To illustrate this, running the following script as args.php arg1 arg2 arg3 : #!/usr/bin/php <?php var_dump(

Passing a class as an argument to a method in java

狂风中的少年 提交于 2019-11-29 13:21:45
I am writing a method were I would like to pass a class to a method, where a part of the code includes checking if the object is of a certain type. This is what I want (but which obviously doesn't work): private static class MyClass1 { /***/ } private static class MyClass2 { /***/ } private void someFunc() { /* some code */ methodName(MyClass1); methodName(MyClass2); } private void methodName(Class myClass) { Object obj; /* Complicated code to find obj in datastructure */ if (obj instanceof myClass) { /* Do stuff */ } } Any hints as to how this can be done? Thanks! Class has both an isInstance

How do I globally change a variable value within function in lisp

怎甘沉沦 提交于 2019-11-29 12:13:45
I would like to know if there is any way to mimic C behaviour with pointers in LISP. In C if you change a value of a variable, that pointer is pointing to, it has a global effect (i.e. the value will be changed outside the function too). So if I had (defun mutate ( a ) (some-magic-function a 5) ) a would turn to 5 after calling mutate, no matter what it was before. I know it is possible (much of as a side effect) with elements with lists In common-lisp, how do I modify part of a list parameter from within a function without changing the original list? but I would like to know how to do it for

Argument conversion: (normal) pointer to void pointer, cast needed?

纵然是瞬间 提交于 2019-11-29 10:37:57
When assigning to or from a void -pointer no cast is needed (C99 §6.3.2.2 sub 1 / §6.5.16.1 sub 1). Is this also true when passing a (for example int -)pointer to a function that expects a void -pointer? For example: void foo(void * p){ // Do something } int main(){ int i = 12; foo(&i); // int * to void *: no cast needed? } When I compile this with GCC (4.8.1, MinGW-32) I get neither errors nor warnings (with -Wall & -pedantic ). In contrast in this answer it is suggested that a cast is needed for this call (to eliminate -Wformat warnings): int main(){ int i = 12; printf("%p\n", &i); } But in

How to pass a function and its arguments through a wrapper function in R? Similar to *args and *kwargs in python

时间秒杀一切 提交于 2019-11-29 10:24:08
I want to write a wrapper function in R. I should take a function and its arguments. Do something, and then call the function with the supplied arguments. I know how to do it in python, but I search for an implementation in R. In python I would write: def wrapper(func, *args, **kwargs): #do something here return func(*args, **kwargs) wrapper <- function(func, ...) { func(...) } 来源: https://stackoverflow.com/questions/8165837/how-to-pass-a-function-and-its-arguments-through-a-wrapper-function-in-r-simila

Passing arguments django signals - post_save/pre_save

倖福魔咒の 提交于 2019-11-29 05:59:34
问题 I am working on a notification app in Django 1.6 and I want to pass additional arguments to Django signals such as post_save . I tried to use partial from functools but no luck. from functools import partial post_save.connect( receiver=partial(notify, fragment_name="categories_index"), sender=nt.get_model(), dispatch_uid=nt.sender ) notify function has a keyword argument fragment_name which I want to pass as default in my signals. Any suggestions? 回答1: Your attempt with partial isn't working