Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Chapter 35. Programs: Standing Alone

This chapter will cover additional aspects of creating some common kinds of programs in Python. We'll survey the landscape in the section called “Kinds of Programs”. Then, in the section called “Command-Line Programs: Servers and Batch Processing” will the essence of program startup using command-line options and operands. In the getopt module and show how to properly control the startup of programs of every kind. In the section called “The getopt Module” we'll look at parsing command line options with getopt. In xthe section called “The optparse Module” we'll look at parsing command-line options with optparse.

Interactive graphical user interfaces are beyond the scope of this book. There are several handy graphic frameworks, including Tkinter and GTK that help you write graphical user interfaces. However, GUI programs are still started from the command line, so this section is relevant for those kinds of programs.

Kinds of Programs

There are many design patterns for our application programs. We can identify a number of features that distinguish different kinds of programs. We can create a taxonomy of program designs based on how we interact with them. We could also create a taxonomy based on the program's internal structure or its interfaces.

We can look at a program based on the type of interaction that it has with a person. There's a spectrum of interaction.

  • A program can be started from the command line and have no further interaction with the human user. We can call these batch programs because they usually process a batch of individual transactions. We can also call them command-line programs because our only interaction is at the command prompt. A large number of data analysis and business-oriented programs work with batches of data. Additionally, we can describe servers as being similar to batch programs. This is a focus for this chapter.

  • A program can have very sophisticated interaction with the human user. The interaction may be character-oriented, or it can have a graphic user interface (GUI) and be started by double-clicking an icon. What's important is that the user drives the processing, not the batch of data. Typically, a program with rich user interaction will be a client of one or more services. These programs are beyond the scope of this book.

We can also look at programs based on their structure and how the interact with other programs.

  • Some programs stand alone. They have an executable file which starts things off, and perhaps includes some libraries. Often a client program is a stand-alone program that runs on someone's desktop. This is a focus for this chapter.

  • Some programs plug into a larger and more sophisticated frameworks. The framework is, essentially, a closely related collection of libraries and interfaces. Most web applications are built as programs which plug into a web server framework. There is a tremendous amount of very common processing in handling a web transaction. There's little value in repeating this programming, so we inherit it from the framework.

We can distinguish programs in how they interact with other programs to create a larger system. We'll turn to this topic in the next chapter, Chapter 36, Programs: Clients, Servers, the Internet and the World Wide Web .

  • Some programs are clients. They rely on services provided by other programs. The service it relies on might be a web server or a database server. In some cases, the client program has rich user interaction and stands alone.

  • Some programs are servers. They provide services to other programs. The service might be domain names, time, or any of a myriad of services that are an essential part of Linux and other operating systems.

  • Some programs are both servers and clients of other services. Most servers have no interaction; they are command-line programs which are clients of other command-line programs. A web server typically has plug in web applications which use database servers. A database server may make use of other services within an operating system.

Some Subspecies. Stand-alone, command-line programs have a number of design patterns. Some programs are filters that read an input file, perform an extract or a calculation and produce a result file that is derived from the input. Programs can be compilers, performing extremely complex transformations from one or more input files to create an output file. Programs can be interpreters, where statements in a language are read and processed. Some programs, like the Unix awk utility, combine filtering and interpreting.

Stand-alone, iteractive programs allow a user to create and manipulate data objects. Interactive programs often have sophisticated graphics. All games are interactive progams. The software often characterized as the office suite, including word processors, spread sheets, graphics programs, schedule managers and contact managers are interactive programs.

Some programs are clients of services. For example, browsers take user queries, fetch and format data, and present the data to the user. An FTP client program may display contents of an FTP server, accepting user commands through a graphical user interface (GUI) and transferring files. An IMAP client program may display mailboxes on a mail server, accepting commands and transferring or displaying mail messages.

Many programs combine interaction with being a client of one or more services. Most browsers, like Firefox, are clients for servers which use a number of protocols, including HTTP, POP3, IMAP4, FTP, NNTP, and GOPHER. Besides being a client, a browser also provides graphics, handling numerous MIME data types for different kinds of images and sounds.

Yet another common type of program is a server. These programs are also interactive, but they interact with client programs, not a person through a GUI. An HTTP server like Apache, for instance, responds to browser requests for web pages. An FTP server responds to FTP client requests for file transfers. A server is often a kind of batch program, since it is left running for indefinite periods of time, and has no user interaction.


 
 
  Published under the terms of the Open Publication License Design by Interspire