Project: A command-line search utility
This chapter has been about querying MySQL from Python. As a project to finish it out, we will build a command-line search utility. Rather than ask the user for the search term, we will expect the user to state the term as an argument for the command-line invocation.
Note
With a bit more code for this project, we could create a GUI for this program. GUI programming increases the complexity of the code. How much more complex it gets depends on the library being used, but it is nonetheless unnecessary for what we need to illustrate in this project. Until we are certain that we have a database and can connect to it, it is best to keep it simple.
Now, it is true that we could simply take input and feed it through MySQL for Python as a generic SELECT *
statement. The logic for this bare bones implementation has been illustrated previously to a great extent. We can create something a bit more sophisticated.
The following characteristics should apply to our search...