Running a Python function from Mac terminal [duplicate] - python

This question already has answers here:
How to read/process command line arguments?
(22 answers)
Call function based on argparse
(7 answers)
Closed 7 months ago.
I have a Python script with a few functions.
Is it possible to launch the script from terminal and then leap straight to a particular function, following conditions within the script? I.e. python3 script.py function.
I was thinking this would be a good alternative to asking the user to answer Y/N to starting functions within script.

Related

How to create library that can be ran without typing "python -m" [duplicate]

This question already has answers here:
Running a python package from terminal
(1 answer)
How to add command line tool to python package
(1 answer)
Explain Python entry points?
(3 answers)
Closed 6 months ago.
I'm working on making a python library, and I want it to be similar to pyinstaller or auto-py-to-exe in the sense that once you install it with pip you can just write on the terminal "pyinstaller [actions..]". Basically, it can be used by simply calling it in the command line.

What is the fastest way to execute commands in python? [duplicate]

This question already has answers here:
Speed difference betwen subprocess.call() and os.system()
(1 answer)
fastest way to invoke a process from python?
(1 answer)
Closed 11 months ago.
I'm writing a Python script and I need to call some commands, for example creating directories, deleting files, execute docker commands, git commands, make command etc.
What is the fastest way to invoke such commands?
Should I use os.system or subprocess?
The Python script will run on Windows and Linux.

Run python-script from CMD - windows [duplicate]

This question already has answers here:
How to execute Python scripts in Windows?
(9 answers)
Closed 6 years ago.
I want to run my python script without the python keyword at the beginning.
Example :
I don't want python script.py.
I want script.py
The problem is that when I run it how I want the script opens in a text editor, and it doesn't run in the console...
Why?
I just had to set the default opening of the file with python.exe,
By default it was with VS Code.

How to run batch file using python script? [duplicate]

This question already has answers here:
Run a .bat file using python code
(9 answers)
Closed 6 years ago.
Is this possible? I yes, can anyone help me how to do it. I don't know how to use subprocess and Popen() to run my sort.bat file.
You can use os.system:
import os
os.system('Path to your .bat file')

Linux command line instructions from python [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 7 years ago.
Is there a method for issuing command line instructions directly from the python shell?
You can use os.system -
import os
os.system('<command line instruction>')

Categories

Resources