Questions tagged [positional-parameter]

75 questions
0
votes
1 answer

Why do I get "SyntexError: non-keyword arg after keyworkd arg" when my function doesn't specify keyword arguments in Python?

I read about positional arguments and keyword arguments, but I still don't understand why I get SyntexError: non-keyword arg after keyworkd arg from running the following code. I didn't specify any keyword arguments in my objective function,…
0
votes
0 answers

python *args list of positional parameters

I have a function that takes as input *args: def foo(*args): for a in args: print(a) This works as intended > foo('a', 'b') > a > b I am faced with a situation where I don't know how many args are going to be passed (which is the…
gmarais
  • 1,322
  • 2
  • 12
  • 25
0
votes
1 answer

Run a bash script within Automator using positional parameters

This is my first time using Automator and it seems like a pretty nifty tool. I am running into an issue however at the very end of the automation. The goal of my automator workflow is to specify a path, then create a directory Highschool1, for…
LobsterBoy
  • 15
  • 3
0
votes
0 answers

Iterate through arguments /positional parameters with sub paramaters - BASH

I am having a hard time figuring out how to handle a set of paramters in bash: The script contains mandatory options to set when running it, and those options then have their own parameters that I would like the script to handle in a case specific…
0
votes
1 answer

In Bash scripting, how to change directory to a file's directory path using the function `dirname`?

I would like to change directory to that of a file by defining an alias: alias direc=`cd | echo dirname "$1"` but this doesnt work. Any ideas are appreciated for how I can restructure this.
user321627
  • 1,916
  • 1
  • 11
  • 31
0
votes
0 answers

ruby method arguments writen after method name and space leads to error

I write a method. def additionner (x,y) puts (x * y) end additionner(2,7) It works, but if I make a space after calling the method, it doesn’t work, why? Note that there is no difference wether there is a space between the method name and…
kouty
  • 324
  • 7
  • 16
0
votes
1 answer

Tokenize string - wrong result

Wrong tokenize of string For extraction of app version from command output #!/bin/bash # GNU bash, version 4.3.46 string='Version: 19.08.19-14:25' IFS=" -:" set -- $string echo $2 I expect that $2 will have value 19.08.19. But result is 19.08.19…
Mikola
  • 627
  • 4
  • 15
0
votes
2 answers

TypeError: __init__() takes 2 positional arguments but 4 were given

My code is giving the error as TypeError: __init__() takes 2 positional arguments but 4 were given. tried searching for an extra argument but couldn't get one. Tried previously answered questions but didn't get any proper solution. My code is as…
Vikesh Patil
  • 11
  • 2
  • 5
0
votes
2 answers

Parameter is not visible in function

I am writing a script, where I need to work with parameters. Here is my foo.sh: say_hello() { if [ "$1" == "hello" ] then echo "hello" else echo "<$1>" fi } echo "$1" say_hello The output looks very strange for me: hello <> Could…
Laughing_Man
  • 63
  • 10
0
votes
3 answers

What is the meaning of opts=${1:+--host $1} in bash?

In a bash script, I stumbled upon this piece of code: opts=${1:+--host $1} /path/somecmd $opts somesubcmd By testing, I found out that $opts expands to --host $1 whatever $1 is. I wonder what is the purpose of this syntax. Why not simply use…
LuoLeKe
  • 35
  • 8
0
votes
2 answers

Positional argument follows keyword argument | Error while calling function

First, I understand that while defining function you have to place positional arguments first and then default arguments to avoid the ambiguity situation for interpreter. That is why when we try to do it, it throws an error. For e.g. in the…
0
votes
1 answer

Is *args in Python3 guaranteed to preserve order?

In Python3 i can use * to accept any number of positional arguments. A sample demonstrating this: def a(*args): for argument in args: print(argument) a(1,2,3,4) Would thus print: 1 2 3 4 What I'm uncertain is, if the order of…
0
votes
2 answers

How to map function on all argument values, as a list? but have explicit argument names in the function definition

I want to define a function using explicit argument names ff(a,b,c) in the function definition, but I also want to map a function over all arguments to get a list: ff(a,b,c): return list(map(myfunc,[a,b,c])) However, I don't want to explicitly…
user15964
  • 2,071
  • 1
  • 22
  • 48
0
votes
1 answer

Django Forms - Why is Button SUBMIT a "positional argument" to a Python function?

Have a simple function within a class . Function is as below :- def addition(a,b): return a+b Want the user to enter Two Numeric values within a Django Form , then add up these and show a result . Within the HTML Page have code as below :-…
Rohit Dhankar
  • 1,168
  • 12
  • 22
0
votes
3 answers

BASH shell execution from string with positional parameters

When I try to run the code below, the shell is replacing (because they are not defined as a bash variable) $4 and $2 with blanks. My question is, how do I keep bash from trying to evaluate the positional parameters for awk as its variables? I've…
user3308131
  • 149
  • 1
  • 4
  • 14