Executing multiple python commands in linux [duplicate] - python

This question already has answers here:
Run text file as commands in Bash
(5 answers)
Closed 8 years ago.
I have multiple commands in a file in the following format
python dosomething.py arg1 arg2
python dosomethingelse.py arg1 arg2
I want to execute one by one.
What is the elegant way of doing it.
Thanks

If you have those lines in a file (say, run-python-scripts.sh), you can run it with sh:
sh run-python-scripts.sh

Related

Difference between "main.py" and "python main.py" in command prompt [duplicate]

This question already has answers here:
Should I put #! (shebang) in Python scripts, and what form should it take?
(15 answers)
what's the difference between ./script.sh and bash script.sh
(5 answers)
Difference Between Running Python File as Executable vs. Running from Command Line?
(3 answers)
Differences in the ways to running Python scripts
(2 answers)
Closed 2 years ago.
I would like to understand what is the difference between the two commands
python main.py and main.py to run the main.py file in the command prompt; and which to use in what circumstance.

How can I run inline Python code in a command-line shell? [duplicate]

This question already has answers here:
How to execute Python inline from a bash shell
(4 answers)
Closed 2 years ago.
In a shell, I can execute AppleScript command-line code like so:
osascript -e "tell application \"Finder\" to activate"
Is the same thing possible in Python, e.g.:
python --execute "print('hello world!')"
Something like this should work for you!
python -c 'print("Hi")'
Probably a duplicate of How to execute Python inline from a bash shell

Using pytest from a BAT file [duplicate]

This question already has answers here:
How to start Python virtual environment in .bat batch file?
(2 answers)
Closed 2 years ago.
I am trying to using pytest from a BAT file. I have tried something like this
..\venv\Scripts\activate.bat
pytest -v src/datasets_test.py::TestDatasetsOperations::test_dataset_add
But it seems to do nothing. How can I make it work?
EDIT: the question is similar, but no one will go to other question if he thinks the error is with pytest
In order to call another script from a batch script, you need to use call.
call ..\venv\Scripts\activate.bat
pytest -v src/datasets_test.py::TestDatasetsOperations::test_dataset_add

how to run command line python scripts within my code [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 2 years ago.
there are some scripts that you have to run them from command line like
python run.py -u alex__a -p 123 -v -f
I want to work with them inside my code I don't know whats the name of them so I wasn't able to google about my question . sorry if it't so simple
You are looking for sys.argv to access them. Here is a tutorial:
https://www.pythonforbeginners.com/system/python-sys-argv
If you want to get more serious and use a package to do this more elegantly, you should research the argparse package which is excellent and very intuitive to use.

Run Rsync from Python [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 9 years ago.
I need to run an rsync command from Python. Is this possible and if so, how do I do it?
rsync -Ccavz --delete DJStatic username#website
You can call a subprocess from python using the following snippet
import subprocess
subprocess.call(["ls", "-l"])
In your case, it would be something like this
subprocess.call(["rsync", "-Ccavz", "--delete","DJStatic", "username#website"])
See here for more details.

Categories