Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a python function from bash script

I have an "alarm email" function inside a python module. I want to be able to call this function from a bash script. I know you can call a module using 'python ' in the script, but I'm not if you can or how you would call a specific function within the module.

like image 395
Daniel Avatar asked Jan 22 '10 19:01

Daniel


People also ask

Can you run a Python script in a bash script?

We can make use of the bash script to run the Python script in macOS/Ubuntu. Both these operating systems support bash scripts. Let's see the steps to run Python scripts using a bash script. Open any text editor.

How do you call a function in bash?

To invoke a bash function, simply use the function name. Commands between the curly braces are executed whenever the function is called in the shell script. The function definition must be placed before any calls to the function.

What is %% bash in Python?

%%bash. Means, that the following code will be executed by bash. In bash $() means it will return with the result of the commands inside the parentheses, in this case the commands are: gcloud config list project --format "value(core.project)" Google cloud has its own command set to control your projects.


1 Answers

python -c'import themodule; themodule.thefunction("boo!")' 
like image 200
Alex Martelli Avatar answered Sep 22 '22 03:09

Alex Martelli