Chapter 11. Python
If you are not familiar with Python and you do a lot of Perl programming, you definitely want to take a look at it. Python is an object-oriented scripting language that combines the strengths of languages like Perl and Tcl with a clear syntax that lends itself to applications that are easy to maintain and extend. The O’Reilly & Associates, Inc. book Learning Python by Mark Lutz and David Asher provides an excellent introduction into Python programming. This chapter assumes a working understanding of the Python language, including the ability to add new modules into a Python installation.
The Python support for the MySQL and mSQL databases that we are exploring in this chapter comes in the form of two Python modules. At the time of this book’s printing, the mSQL module was available at http://www.python.org and the MySQL module at http://www.mysql.com. While there are several other modules providing MySQL and mSQL access to Python applications, they—like these two—are mostly API variations on the MySQL and mSQL C APIs. You need to install one or both of these modules in order to access your database of choice and run the examples in this chapter.
Both APIs are virtually the same. We will, therefore, approach both modules together and note where they differ.
Basic Connectivity
The Python APIs are likely the simplest database APIs of any in this book. As with the other APIs, we need to start with database connectivity—making the connection. Because Python has an interactive ...
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.