""load table from comma-delimited text fileequivalent to this nonportable sqlload data local infile 'data txtinto table people fields terminated by ','""import sqlite conn sqlite connect('dbase 'curs conn cursor(file open('data txt'rows [line rstrip(split(','for line in filefor rec in rowscurs execute('insert into people values (???)'recconn commit(conn close(commit changes nowif db supports transactions close__del__ call rollback if changes not committed yet as isexample - is top-level script geared toward one particular case it' hardly any extra work to generalize this into function that can be imported and used in variety of scenariosas in example - -- much more widely useful module and command-line script example - pp \dbase\sql\loaddb py ""load table from comma-delimited text filereusable/generalized version importable functionscommand-line usageloaddb py dbfiledatafiletable""def login(dbfile)import sqlite conn sqlite connect(dbfilecurs conn cursor(return conncurs create or open db file def loaddb(curstabledatafileconn=noneverbose=true)file open(datafilex, , \nx, , \ rows [line rstrip(split(','for line in file[[ , , ][ , , ]rows [str(tuple(rec)for rec in rows["( , , )""( , , )"for recstr in rowscurs execute('insert into table values recstrif connconn commit(if verboseprint(len(rows)'rows loaded'if __name__ ='__main__'import sys dbfiledatafiletable 'dbase ''data txt''peopleif len(sys argv dbfile sys argv[ if len(sys argv datafile sys argv[ if len(sys argv table sys argv[ conncurs login(dbfileloaddb(curstabledatafileconn databases and persistence