for the insert statement (see its comments for the transforms appliedwe could also use an executemany call as we did earlierbut we want to be general and avoid hardcoding the fields insertion template--this function might be used for tables with any number of columns this file also defines login function to automate the initial connection calls--after retyping this four-command sequence enough timesit seemed prime candidate for function in additionthis reduces code redundancyin the futuresuch logic need only be changed in single location if we change database systemsas long as the login function is used everywhere table display script once we load datawe probably will want to display it example - allows us to display results as we go--it prints an entire table with either simple display (which could be parsed by other toolsor formatted display (generated with the dictionaryrecord utility we wrote earliernotice how it computes the maximum field-name size for alignment with generator expressionthe size is passed in to string formatting expression by specifying an asterisk (*for the field size in the format string example - pp \dbase\sql\dumpdb py ""display table contents as raw tuplesor formatted with field names command-line usagedumpdb py dbnametable[-(dash=formatted display""def showformat(recssept=('- ))print(len(recs)'records'print(septfor rec in recsmaxkey max(len(keyfor key in recfor key in recprint('%-* =% (maxkeykeyrec[key])print(septmax key len or\ align -ljust*len def dumpdb(cursortableformat=true)if not formatcursor execute('select from tablewhile truerec cursor fetchone(if not recbreak print(recelsefrom makedicts import makedicts recs makedicts(cursor'select from tableshowformat(recsif __name__ ='__main__'import sys dbnameformattable 'dbase 'false'peoplesql database interfaces