TechieYan Technologies

Create a Command Line Application with Python

Abstract

A command-line software is a manner of giving operating gadget instructions using strains of text. Command-line packages perform via the command line or PowerShell. It will engage with a command-line script.

Libraries:

Argparse: Python comes with several one of a kind libraries that permit us to put in writing a command-line interface for our scripts, however the widespread way for developing a CLI in Python is through the usage of the Python argparse module. The argparse module enables us to parse the arguments passed with the script and system them extra quite simply.

Sys: Python presents the sys module that gives us independence from the host gadget working system and allows us to function on an underlying interpreter, irrespective of its being a Linux or windows Platform. With the help of the sys module, we can get admission to device-particular parameters and functions. It provides exclusive functions used to control unique parts of the Python Runtime surroundings.

Python Command Line Application

Code Description & Execution

Program Methodology

This project is created to perform operations using single command. In the program main function is defined. A variable parser is defined in which argparse .argumentparser class is used  in main function add argument is passed as we creating this program to perform calculations   using a command in this aegument x is passed as variable which stores the entered value as  float datatype same is done for another parameter y. Another argument is passed to perform add or any other type of arithematic operations . 

A function is defined calc with parameter args after which if statement is used when args.o is equal to add perform add operation and return the values same is continued for other operations also. If any other operations other calculations is passed it displays something went wrong.

  

How to Execute?

Note: Make sure you have added path while installing the software’s.

http://techieyantechnologies.com/2022/07/how-to-install-anaconda/

http://techieyantechnologies.com/2022/06/get-started-with-creating-new-environment-in-anaconda-configuring-jupyter-notebook-and-installing-libraries-using-requirements-txt-2/

  1. Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.
  2. Press windows key and type in an anaconda prompt a terminal opens up.
  3. Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
  4. <<directory of your file:>>. E.g., If my file is in d drive, then.
  5. Type d:
Command Line Application execution
  1. cd d:\License-Plate-Recognition-main    #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
Command Line Application code execution

          7. If your project is in c drive, you can ignore step 4 and go with step 5

          8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name”.

Results

Python Command Line Application

Issues Faced

  1. We might face an issue while installing specific libraries, in this case, you might need to install the libraires manually. Example: pip install “module_name/library” i.e., pip install pandas
  2. Make sure you have the latest or specific version of python, since sometimes it might cause version mismatch.

Click Here To Download This Code And Associated File.

 

+91 7075575787