If I have a certain function in my shell script, can I call that function from an external python script?
-
Please make your question clearer. What is "my shell script" and how do you run it? How do you run the "external Python script" (external to what?) It's not at all clear what you want to do; it would help a lot to include some sample code.rici– rici2015-03-23 15:49:14 +00:00Commented Mar 23, 2015 at 15:49
Add a comment
|
1 Answer
Here is some reference material as I not exactly sure what you are trying to do:
You can use the Python subprocess module:
from subprocess import call
call(["ls", "-l"])
Or if you are trying to run a specific function from inside your shell script it would be wiser to recode that function in Python. A similar SO question can be found here:
3 Comments
rici
How does this address the question of invoking shell functions?
logic
@rici There literally is no way you can execute a specific shell script function from Python. You'd have to implement the function in Python itself and then use the subprocess module to execute it.
rici
That's not actually quite true. If the shell is bash and the function is exported to the environment, you can run it by executing
bash -c the_function. But anyway, your comment at least addresses the OP, and I suggest you include it in your answer.