Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

You're reading from  Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781783551590
Pages 200 pages
Edition 1st Edition
Languages
Author (1):
Dan Nixon Dan Nixon
Profile icon Dan Nixon

Command-line interface


Now that the framework for the unit conversion is complete, we can start work on the command line interface, used to form the full application.

We will expand the application to include a command line interface by creating a new file named CLI.py in the unitconverter directory. We will start this file by including the required modules and functions:

import argparse
import inspect
from Converter import get_table, convert_units

The run_cli() function is going to be called whenever the unit conversion application is invoked from the command line. It is responsible for parsing the input from the command line and performing the required conversions. This starts by creating a ArgumentParser object, to which we can add arguments that are to be parsed from the command line:

def run_cli():
    parser = argparse.ArgumentParser(description='Tool for converting units')

The first argument will be used to define the conversion table that will be used in the unit conversion:

    parser...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}