if input('are you sure?'lower(not in (' ''yes')sys exit(dbname sys argv[ if len(sys argv else 'dbase table sys argv[ if len(sys argv else 'peoplefrom loaddb import login conncurs login(dbnamecurs execute('delete from table#print(curs rowcount'records deleted'conn commit(conn closed by its __del__ else rows not really deleted finallyexample - provides command-line tool that runs query and prints its result table in formatted style there' not much to this scriptbecause we've automated most of its tasks alreadythis is largely just combination of existing tools such is the power of code reuse in python example - pp \dbase\sql\querydb py ""run query stringdisplay formatted result table examplequerydb py dbase "select namejob from people where pay ""import sys databasequerystr 'dbase ''select from peopleif len(sys argv database sys argv[ if len(sys argv querystr sys argv[ from makedicts import makedicts from dumpdb import showformat from loaddb import login conncurs login(databaserows makedicts(cursquerystrshowformat(rowsusing the scripts last but not leasthere is log of session that makes use of these scripts in commandline modeto illustrate their operation most of the files also have functions that can be imported and called from different programthe scripts simply map commandline arguments to the functionsarguments when run standalone the first thing we do is initialize testing database and load its table from text file\pp \dbase\sqlmakedb py testdb are you sure? database table did not exist made testdb people \pp \dbase\sqlloaddb py testdb data txt rows loaded sql database interfaces