7.7 Summary

7.7 Summary

In this chapter, we've learned about exceptions ”both how to catch them with try statements and how to trigger them with raise statements. Exceptions are identified by string objects or class objects; built-in exceptions are predefined class objects in Python 1.5, but user -defined exceptions may be strings or classes. Either way, exceptions let us jump around programs arbitrarily, and provide a coherent way of dealing with errors and other unusual events. Along the way, we studied common exception idioms, touched on error handling in general, and saw a variety of ways to catch and match raised exceptions.

This chapter concludes our look at the core Python programming language. If you've gotten this far, you can consider yourself an official Python programmer; you've already seen just about everything there is to see in regards to the language itself. In this part of the book, we studied built-in types, statements, and exceptions, as well as tools used to build-up larger program units ”functions, modules, and classes. In general, Python provides a hierarchy of tool sets:

Built-ins

Built-in types like strings, lists, and dictionaries make it easy to write simple programs fast.

Python extensions

For more demanding tasks , we can extend Python in Python, by writing our own functions, modules, and classes.

C extensions

Although we don't cover them in this book, Python can also be extended with modules written in C or C++.

Because Python layers its tool sets, we can decide how complicated we need to get for a given task. We've covered the first two of the categories above in this book already, and that's plenty to do substantial programming in Python.

The next part of this book takes you on a tour of standard modules and common tasks in Python. Table 7.2 summarizes some of the sources of built-in or existing functionality available to Python programmers, and topics we'll explore in the remainder of this book. Up until now, most of our examples have been very small and self-contained. We wrote them that way on purpose, to help you master the basics. But now that you know all about the core language, it's time to start learning how to use Python's built-in interfaces to do real work. We'll find that with a simple language like Python, common tasks are often much easier than you might expect.

Table  7.2. Python's Built-in Toolbox

Category

Examples

Object types

 lists, dictionaries, files, strings 

Functions

 len, range, apply, open 

Modules

 string, os, Tkinter, pickle 

Exceptions

 IndexError, KeyError 

Attributes

 __dict__, __name__ 

Peripheral tools

 NumPy, SWIG, JPython, PythonWin 


Learning Python
Learning Python: Powerful Object-Oriented Programming
ISBN: 0596158068
EAN: 2147483647
Year: 1999
Pages: 156
Authors: Mark Lutz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net