Skip to content
Advertisement

merge python script and data (command) file into single .py file

Below scrip reads lines of commands to execute from a cmdAll.txt. Is there a way that I merge the command file into the script file itself. I remember I have seen such data blocks using <<EOF somewhere but I am not sure how to do it.

myScript.py file:

JavaScript

cmdAll.txt file:

JavaScript

Advertisement

Answer

I think the <<EOF bit you saw somewhere had to do with running Python in a shell script in a shell script, but you’re asking for the inverse. You want your shell commands to live in your python script.

If you’re not going to read the commands from a .txt file, and you would rather they live in the script, you might as well just make it clean and make a list out of them.

JavaScript

If you prefer the commands exist as a single string, you could do something like this, where you are splitting on newlines. Just as Eric Jin suggested

JavaScript
Advertisement