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

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.

Related

Call a powershell script (on a network drive) from python? [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 4 years ago.
How do I call a powershell script from python but the ps script lies on a network drive?
Did you try?
import subprocess
subprocess.call("powershell \\path\to\script.ps1")

redirect python screen output in a file instantly under bash [duplicate]

This question already has answers here:
How to make output of any shell command unbuffered?
(5 answers)
Disable output buffering
(16 answers)
Closed 5 years ago.
once i run a python script under bash by
python a.py >> output.txt
it is found that the screen output is not written to output.txt instantly. is there any way to ensure that output.txt could always up-to-date as we see it on the screen without redirection?
some reference: this has helped python write to file instantly. i am wondering if we can do the same thing for screen output as well.

How to Run a bash script within python pycharm command line? [duplicate]

This question already has answers here:
Running bash script from within python
(7 answers)
Closed 5 years ago.
I am trying to run bash script.sh file in Python.
I tried running it through following code:
subprocess.call("script.sh", shell=True)
but it runs the script outside python and asks Windows application to run this file.
I want this script.sh to be run in Python command line.
I want Python to run this script.
Import the library OS and then use os.system:
import os
os.system('bash')

Executing multiple python commands in linux [duplicate]

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

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