Questions tagged [args]

Common abbreviation for "arguments", often used in reference to command-line arguments or function arguments.

A program can accept any number of arguments from the command line. This allows the user to specify configuration information when the program is launched.

The user enters command-line arguments when invoking the application and specifies them after the name of the command to be run.

898 questions
1542
votes
11 answers

Use of *args and **kwargs

So I have difficulty with the concept of *args and **kwargs. So far I have learned that: *args = list of arguments - as positional arguments **kwargs = dictionary - whose keys become separate keyword arguments and the values become values of these…
MacPython
  • 17,901
  • 10
  • 42
  • 48
66
votes
9 answers

Parsing arguments to a Java command line program

What if I wanted to parse this: java MyProgram -r opt1 -S opt2 arg1 arg2 arg3 arg4 --test -A opt3 And the result I want in my program is: regular Java args[] of size=4 org.apache.commons.cli.Options[] of size=3 org.apache.commons.cli.Options[] #2…
djangofan
  • 28,471
  • 61
  • 196
  • 289
50
votes
6 answers

How do you pass arguments from command line to main in Flutter/Dart?

How would you run a command and pass some custom arguments with Flutter/Dart so they can then be accessed in the main() call such as: flutter run -device [my custom arg] So then I can access it with: void main(List args) { …
Miguel Ruivo
  • 16,035
  • 7
  • 57
  • 87
37
votes
1 answer

accessing the $args array in powershell

I have a test powershell V2 script that looks like this: function test_args() { Write-Host "here's arg 0: $args[0]" Write-Host "here's arg 1: $args[1]" } test_args If I call this from the powershell command prompt I…
larryq
  • 15,713
  • 38
  • 121
  • 190
34
votes
6 answers

C# check if you have passed arguments or not

I have this code: public static void Main(string[] args) { if (string.IsNullOrEmpty(args[0])) // Warning : Index was out of the bounds of the array { ComputeNoParam cptern = new ComputeNoParam(); …
robertpas
  • 643
  • 5
  • 12
  • 25
26
votes
3 answers

Python converting *args to list

This is what I'm looking for: def __init__(self, *args): list_of_args = #magic Parent.__init__(self, list_of_args) I need to pass *args to a single array, so that: MyClass.__init__(a, b, c) == Parent.__init__([a, b, c])
Daniel Watson
  • 463
  • 1
  • 4
  • 9
23
votes
6 answers

Python Command Args

I have been googling almost an hour and am just stuck. for a script, stupidadder.py, that adds 2 to the command arg. e.g. python stupidadder.py 4 prints 6 python stupidadder.py 12 prints 14 I have googled so far: import argparse parser =…
user1601118
  • 397
  • 1
  • 2
  • 6
20
votes
3 answers

How to convert all arguments to dictionary in python

I would like to my function func(*args, **kwargs) return one dictionary which contains all arguments I gave to it. For example: func(arg1, arg2, arg3=value3, arg4=value4) should return one dictionary like this: {'arg1': value1, 'arg2': value2,…
nimi
  • 391
  • 1
  • 2
  • 10
20
votes
3 answers

Proper terminology for Object... args

I'm working in Java and the typical way you specify multiple args for a method is: public static void someMethod(String[] args) But, I've seen another way a few times, even in the standard Java library. I don't know how to refer to this in…
SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
19
votes
2 answers

Swift function with args... pass to another function with args

I have a simple problem. I tried search in many blogs about this question but all site return how function in swift work, but I need this case. My custom function is: func getLocalizeWithParams(args:CVarArgType...)->String { return…
ViTUu
  • 1,204
  • 11
  • 21
17
votes
2 answers

How to pass quoted args to GNU Parallel

I need to pass some text that includes whitespace and other characters to a script that's being run by GNU Parallel. Here is a very simple example: $ seq 1 3 | parallel echo "Quoted ' (text)" The above example will output this: sh: -c: line 0:…
chaimp
  • 16,897
  • 16
  • 53
  • 86
16
votes
3 answers

args and kwargs in django views

Okay, I've tried searching for this for quite some time. Can I not pass args and kwargs to a view in a django app? Do I necessarily have to define each keyword argument independently? For example, #views.py def someview(request, *args,…
Sidd
  • 1,168
  • 2
  • 10
  • 27
15
votes
3 answers

What does wp_parse_args do?

I've been building Wordpress widgets for a while and have always used some code like this: $instance = wp_parse_args( (array) $instance); It's never caused problems and is recommended in several places (by Justin Tadlock, two Wordpress books I…
ggwicz
  • 568
  • 1
  • 5
  • 20
14
votes
2 answers

pandas, apply with args which are dataframe row entries

I have a pandas dataframe 'df' with two columns 'A' and 'B', I have a function with two arguments def myfunction(B, A): # do something here to get the result return result and I would like to apply it row-by-row to df using the 'apply'…
Runner Bean
  • 4,895
  • 12
  • 40
  • 60
14
votes
1 answer

Golang - Check number of arguments? Also User Input - Check for return key (blank line) entry ""

Two questions. 1...I am writing a little game that requires an argument to be provided by the user on the command line. The command line entry would look like "go run game.go 8". os.Args[0] is the program run (game.go), and os.Args[1] is the…
user1945077
  • 161
  • 1
  • 1
  • 6
1
2 3
59 60