0

Suppose I have two functions function_arguments1 and function_agruments2 which are accepting parameters. I want to call the function name:- function_argument1, from python script. How should I call the function_arguments1 from Python passing parameters from python script.

#!/bin/bash  
#Script to pass and access arguments  
  
function_arguments1(){  
    echo $1  
    echo $2  
    echo $3  
    echo $4  
    echo $5  
}  
  

function_argument2(){
    echo $1  
    echo $2  
}

#Calling function_arguments2  
function_arguments2 "Please""Help" 

3

1 Answer 1

1
import subprocess

subprocess.Popen(['bash', '-c', '. bash_script.sh; function_argument2 Please Help'])

To pass input arguments from a list:

inputs = ['Hello', 'How', 'What']

for input_ in inputs:
       subprocess.Popen(['bash', '-c', f'. bash_script.sh; function_argument2 {input_}'])
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much working ... I had spent 1 week to figure out this thing. Thank You so much 😊
Hey, i have one doubt lets say i have to repeat this process again and again. so i will the for loop like for i in function_call_list: (function call list is a list of parameters say ['Hello', 'How', 'What']. So when i write the subprocess.Popen(['bash', '-c', '. bash_script.sh; function_argument2 i ']) i value it is not taking. what should i do
I have updated the answer with the solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.