php default arguments [duplicate]

Passing null or “” for a parameter you don’t want to specify still results in those nulls and empty strings being passed to the function. The only time the default value for a parameter is used is if the parameter is NOT SET ALL in the calling code. example(‘a’) will let args #2 and #3 … Read more

Gradle task – pass arguments to Java application

Gradle 4.9+ gradle run –args=”arg1 arg2″ This assumes your build.gradle is configured with the Application plugin. Your build.gradle should look similar to this: plugins { // Implicitly applies Java plugin id: ‘application’ } application { // URI of your main class/application’s entry point (required) mainClassName=”org.gradle.sample.Main” } Pre-Gradle 4.9 Include the following in your build.gradle: run … Read more

dotnet ef scaffold Unrecognized option ‘-t firstTable -t secondTable’ – pass arguments stored in a string

If you construct a string such as -t foo and pass it via a variable to an external program, it is passed as a single, double-quoted argument (that is, donet will literally see “-t foo” on its command line) – and therefore won’t be recognized as parameter name-value combination. You must pass -t and foo … Read more

With “args” vs without “args” to pass arguments to a thread in Python

This does not call test in a new thread: thread = threading.Thread(target=test(“Test”)) thread.start() Here’s how Python interprets those lines of code: Main thread calls test(“Test”). test(“Test”) returns None. Main thread calls Thread(target=None).* Main thread starts the new thread. New thread does absolutely nothing at all because its target is None. Edit: *I wondered why Thread(targe=None) … Read more

argparse argument order

To keep arguments ordered, I use a custom action like this: import argparse class CustomAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): if not ‘ordered_args’ in namespace: setattr(namespace, ‘ordered_args’, []) previous = namespace.ordered_args previous.append((self.dest, values)) setattr(namespace, ‘ordered_args’, previous) parser = argparse.ArgumentParser() parser.add_argument(‘–test1’, action=CustomAction) parser.add_argument(‘–test2’, action=CustomAction) To use it, for example: >>> parser.parse_args([‘–test2’, ‘2’, ‘–test1’, ‘1’]) Namespace(ordered_args=[(‘test2’, … Read more