arguments

Why can I have required parameters after a splat in Ruby but not optional ones? [duplicate]

核能气质少年 提交于 2019-12-31 04:43:26
问题 This question already has answers here : How to define a method in ruby using splat and an optional hash at the same time? [duplicate] (5 answers) Closed 5 years ago . This is possible in Ruby: class SomeClass def initialize(a, *b, c) end end but this is not: class SomeClass def initialize(a, *b, c='anything here') end end Why? Edit: This question does NOT have an answer. In the answer linked, the first answer is: The splat means "use up all of the remaining arguments" but then you provide an

Callback function not callable

烈酒焚心 提交于 2019-12-31 04:03:48
问题 I've read in python documentation that it is possible to call a function from command line, so I've used optparse module to return a huge text from a function but my code doesn't work! I think I've done everything right. def HelpDoc(): return """ SOME HUGE TEXT """ parser = OptionParser(usage="%prog ConfigFile") parser.add_option("-g", "--guide", action = "callback", callback=HelpDoc(), help = "Show help documentation") (options,args) = parser.parse_args() Traceback parser.add_option("-g", "-

How to write a multithreaded function for processing different tasks concurrently?

家住魔仙堡 提交于 2019-12-31 04:03:35
问题 I would like to define a do_in_parallel function in python that will take in functions with arguments, make a thread for each and perform them in parallel. The function should work as so: do_in_parallel(_sleep(3), _sleep(8), _sleep(3)) I am however having a hard time defining the do_in_parallel function to take multiple functions with multiple arguments each, here's my attempt: from time import sleep import threading def do_in_parallel(*kwargs): tasks = [] for func in kwargs.keys(): t =

Illegal argument exception: n must be positive

时间秒杀一切 提交于 2019-12-31 03:26:10
问题 main class: public class ECONAPP2 { static Scanner input= new Scanner(System.in); static int score = 0; static ArrayList<Integer> usedArray = new ArrayList<Integer>(); public static void main(String[] args){ app(); arrayContents(); } public static void arrayContents() { usedArray.add(2); usedArray.add(1); } app() method: public static void app() { Random generator = new Random (); int randomNumber = generator.nextInt(usedArray.size()); System.out.println(randomNumber); if (randomNumber == 2)

Is it safe to use the same variable as input and output in C++ OpenCV?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 17:39:43
问题 A lot of OpenCV functions are defined as function(InputArray src, OutputArray dst, otherargs..) So if I want to process and overwrite the same image, can I do this: function(myImg, myImg); is it safe to do this way? Thanks Edit: I'm asking for the standard functions in OpenCV like threshold , blur etc. So I think they should have been implemented accordingly, right? 回答1: Yes, in OpenCV it is safe. Internally, a function like: void somefunction(InputArray _src, OutputArray _dst); will do

How to obtain argparse subparsers from a parent parser (to inspect defaults)

不打扰是莪最后的温柔 提交于 2019-12-30 14:15:11
问题 Suppose that I create a parser with a default value for an argument, and then give it a subparser with a further default value for an argument. In [1]: parser = argparse.ArgumentParser(description='test') In [2]: parser.add_argument("--test", dest="test", default="hello") Out[2]: _StoreAction(option_strings=['--test'], dest='test', nargs=None, const=None, default='hello', type=None, choices=None, help=None, metavar=None) In [3]: parser.get_default("test") Out[3]: 'hello' In [4]: subparsers =

Bash Script with Parsing Argument in Linux

假如想象 提交于 2019-12-30 11:17:26
问题 I want to write a bash script : schedsim.sh [-h] [-c x] -i pathfile Where : • -h: print the current username. • -c x : get an option-argument x and print out (x + 1). If no argument was found, print the default value is 1. • -i pathfile: print the size of pathfile. The pathfile is a required argument. If no argument was found, print out an error message. This is what I've done so far : x="" path="" while getopts ":hc:i:" Option do case $Option in h) echo -e "$USER\n" ;; c) x=$optarg+1 ;; i)

Method parameter with (attribute) in brackets

给你一囗甜甜゛ 提交于 2019-12-30 11:07:18
问题 I have a code example from KendoUI. public ActionResult Customers_Read([DataSourceRequest]DataSourceRequest request) { return Json(GetCustomers().ToDataSourceResult(request)); } private static IEnumerable<CustomerViewModel> GetCustomers() { var northwind = new SampleEntities(); return northwind.Customers.Select(customer => new CustomerViewModel { CustomerID = customer.CustomerID, CompanyName = customer.CompanyName, ContactName = customer.ContactName, // ... }); } This example works fine. I am

Method parameter with (attribute) in brackets

末鹿安然 提交于 2019-12-30 11:05:21
问题 I have a code example from KendoUI. public ActionResult Customers_Read([DataSourceRequest]DataSourceRequest request) { return Json(GetCustomers().ToDataSourceResult(request)); } private static IEnumerable<CustomerViewModel> GetCustomers() { var northwind = new SampleEntities(); return northwind.Customers.Select(customer => new CustomerViewModel { CustomerID = customer.CustomerID, CompanyName = customer.CompanyName, ContactName = customer.ContactName, // ... }); } This example works fine. I am

Avoid argument duplication when passing through (…)

人盡茶涼 提交于 2019-12-30 07:51:54
问题 Consider the function f <- function(x, X) mean(c(x,X)) How can I automatically (by manipulation of f() ) change the signature of f() such that it can be used with lapply() , i.e., without returning the following obvious error? lapply(X=list(1), FUN=f, X=1) Error in lapply(X = list(1), FUN = f, X = 1) : formal argument "X" matched by multiple actual arguments The approach I used so far is to remove all arguments from f() , assign them into an environment, and evaluate f() in that environment.