Questions tagged [positional-parameter]

104 questions
1
vote
2 answers

Why positional arguments need to be specified before keyword arguments in Python?

I understand passing positional arguments first and then passing the keyword arguments is a rule in python. And that's why these are wrong: def fun(x,y): print(x,y) fun3(y=4,3) SyntaxError: positional argument follows keyword argument and…
1
vote
1 answer

Powershell A positional parameter cannot be found that accepts argument '10'. While not even using a positional parameter

Note that the example code is contrived and is meant for illustration of the problem only. I wanted to make a function in powershell to get some random numbers but i'm running into the very weird issue that when i dont use the position defining of…
smvd
  • 117
  • 2
  • 11
1
vote
2 answers

How to use positional argument with embed quotes in bash?

I'm trying to create a bash script that automates configuration of some letsencrypt related stuff. The file that I have to edit is json so I would just use jq to edit it and pass the site name to it from the positional arguments of the script, but I…
The amateur programmer
  • 1,238
  • 3
  • 18
  • 38
1
vote
2 answers

Bash - how to get a last character of a positional Parameter?

I am trying to read a last character of a string saved in a positional parameter $1. So far, I know how to do this only for the named variable, such as echo "${str: -1}" Could someone advise me how to do it for $1. Thought this could work, but it…
Jozef
  • 479
  • 1
  • 9
  • 36
1
vote
2 answers

How do I pass multiple arguments to a shell script into `kubectl exec`?

Consider the following shell script, where POD is set to the name of a K8 pod. kubectl exec -it $POD -c messenger -- bash -c "echo '$@'" When I run this script with one argument, it works fine. hq6:bot hqin$ ./Test.sh x x When I run it with two…
merlin2011
  • 71,677
  • 44
  • 195
  • 329
1
vote
0 answers

pandas dataframe calling apply as a class variable: takes 1 positional argument but 2 were given

I am running into a weird python error that I could not understand: import pandas as pd import numpy as np def logit(p): if 0 < p < 1: return np.log(p / (1 - p)) elif p == 0 or p == 1: return pd.NA else: raise…
qkhhly
  • 1,150
  • 3
  • 12
  • 27
1
vote
1 answer

SystemError is raised after attempt to create function with positional-only args in runtime inside other one

There is some test code: some_type = int def func0(): def func1(arg: some_type, /): pass func0() And I get the following error: Traceback (most recent call last): ... SystemError: no locals when loading 'some_type' However the code…
1
vote
0 answers

Command line using an array with spaces

How can I pass an array where some values have spaces. I mean: script.sh #/bin/bash echo $1, $# I can run this little script $ ./script.sh a --> a, 1 $ ./script.sh "a b" --> a b, 1 $ v=("a b" c) $ ./script.sh ${v[@]} --> a, 3 $ ./script.sh…
user721730
  • 438
  • 1
  • 7
  • 11
1
vote
1 answer

Bash - How to pass array to function, with index defined in new function

I have this current function used to create an array in a menu style (associative arrays can't be used in the scenario). declare -a array1=("host1" "host2" "host3") declare -a array2=("ip1" "ip2" "ip3") function menusetup { iter=0 for ((i=0;…
1
vote
3 answers

bash function with three to infinitely arguments

Lets assume I have some python argparse script which I would like to kind of alias using a bash function. Let us assume this python script takes four arguments: --arg1 --arg2 --arg3 --arg4 What I would like to achieve is taking the first two…
Peterhack
  • 941
  • 4
  • 15
  • 34
1
vote
1 answer

How do you specify both static and dynamic positional parameters in Powershell?

EDIT As per The Mad Technician's suggestion, I have submitted a bug report for this on the PowerShell UserVoice site:…
1
vote
4 answers

setting a positional parameter in a function in bash

I'm making a function to easly convert my strings to arrays as I need to. I am somewhat running into a weird issue. I am still new to bash and this is really bugging me. Would anybody be able to shed some light onto…
IT kid
  • 43
  • 4
1
vote
1 answer

accessing a positional parameter through a variable

I'm trying to access a positional parameter using a variable. i.e. if I define a variable as 1, I want to access the 1st positional parameter, if I define it as 2 I want to access the 2nd positional parameter. example: bash script.bash arg1 arg2…
Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
1
vote
2 answers

How do I print the help interface on argparse with 2 positional arguments?

I'm learning the basics of argparse, and I have made a program that prints information on the solar system in the command line, however, I have used 2 positional arguments which is causing some complications. My aim is to print the 'help' interface…
cact1
  • 11
  • 2
0
votes
2 answers

GET/POST request with additional non named parameter using python requests

I'm currently dealing with the implementation of a Anel Power Outlet manager. The Anel power outlet supports the following requests: https://forum.anel.eu/viewtopic.php?f=52&t=888&sid=39081b8e472aaae7ffcec4cd3fb41e83 However, the special form of the…