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

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

  




 

 

Components, Modules and Packages

Delivering Components as Modules and Packages

The basic Python language is rich with features. These include several sophisticated built-in data types (Part II, “Data Structures”), numerous basic statments (Part I, “Language Basics”), a variety of common arithmetic operators and a library of built-in functions. In order to keep the basic Python kernel small, relatively feature features are built-in. A small kernel means that Python interpreters can be provided in a variety of software application, extending functionality of the application without bloating due to a large and complex command language.

The more powerful and sophisticated features of Python are separated into extension modules. There are several advantages to this. First, it allows each program to load only the relevant modules, speeding start-up. Second, it allows additional modules to be added easily. Third, it allows a module to be replaced, allowing you to choose among competing solutions to a problem.

The second point above, easily adding modules, is something that needs to be emphasized. In the Python community, this is called the batteries included principle. The ideal is to make Python directly applicable to just about any practical problem you may have.

Some modules have already been covered in other chapters. In the section called “The math Module” we covered math and random modules. In Chapter 12, Strings we covered the string module.

Overview of this part. This part will cover selected features of a few modules. The objective is to introduce some of the power of key Python modules and show how the modules are used to support software development. This isn't a reference, or even a complete guide to these modules. The standard Python Library documentation and other books describe all available modules in detail. Remember that Python is an open-source project: in some cases, you'll have to read the module's source to see what it really does and how it works.

This part provides a general overview of how to create Python modules in Chapter 28, Modules . It also covers how to create packages in Chapter 30, The Python Library . An overview of the Python library is the focus of Chapter 30, The Python Library .

Module Details. We cover several essential modules in some detail.

Programs -- The Ultimate Modules. In a sense a top-level program is a module that does something useful. It's important understand "programs" as being reusable modules. Eventually most really useful programs get rewritten and merged into larger, more sophisticated programs.

In Chapter 35, Programs: Standing Alone this part covers modules essential for creating polished, complete stand-alone programs. This includes the getopt and optparse modules.

The final chapter covers integration among programs using the client-server programming model. This includes a number of modules that are essential for creating networked programs.

Table of Contents

28. Modules
Module Semantics
Module Definition
Module Use: The import Statement
Finding Modules: The Path
Variations on An import Theme
Import As
From Module Import Names
Import and Rename
The exec Statement
Module Exercises
Refactor a Script
Install a New Module
Planning for Maintenance and Upgrades
Style Notes
29. Packages
Package Semantics
Package Definition
Package Use
Package Exercises
Style Notes
30. The Python Library
Overview of the Python Library
Most Useful Library Sections
Library Exercises
31. Complex Strings: the re Module
Semantics
Creating a Regular Expression
Using a Regular Expression
Regular Expression Exercises
32. Dates and Times: the time and datetime Modules
Semantics: What is Time?
Some Class Definitions
Creating a Date-Time
Date-Time Calculations and Manipulations
Presenting a Date-Time
Time Exercises
Additional time Module Features
33. File Handling Modules
The os.path Module
The os Module
The fileinput Module
The tempfile Module
The glob and fnmatch Modules
The shutil Module
The File Archive Modules: tarfile and zipfile
The Data Compression Modules: zlib, gzip, bz2
The sys Module
Additional File-Processing Modules
File Module Exercises
34. File Formats: CSV, Tab, XML, Logs and Others
Overview
Comma-Separated Values: The csv Module
About CSV Files
The CSV Module
Basic CSV Reading
Consistent Columns as Dictionaries
Writing CSV Files
Tab Files: Nothing Special
Property Files and Configuration (or.INI) Files: The ConfigParser Module
Fixed Format Files, A COBOL Legacy: The codecs Module
XML Files: The xml.minidom and xml.sax Modules
Log Files: The logging Module
File Format Exercises
35. Programs: Standing Alone
Kinds of Programs
Command-Line Programs: Servers and Batch Processing
The getopt Module
The optparse Module
Command-Line Examples
Other Command-Line Features
Command-Line Exercises
36. Programs: Clients, Servers, the Internet and the World Wide Web
About TCP/IP
Web Servers and the HTTP protocol
About HTTP
Building an HTTP Server
Example HTTP Server
Web Services: The xmlrpclib Module
Web Services Overview
Web Services Client
Web Services Server
Mid-Level Protocols: The urllib2 Module
Client-Server Exercises
Socket Programming
Client Programs
Server Programs
Practical Server Programs with SocketServer
Protocol Design Notes

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