# L-29 MCS 275 Fri 19 Mar 2010 : scripts_count.py # Counts the number of scripts in the table 'scripts' # in the MySQL database 'OurPyFiles'. # Requirements for a successful run: # (1) MySQL must be started (sudo mysqld_safe); and # (2) run this script as sudo python scripts_count.py. import MySQLdb db = MySQLdb.connect(db='OurPyFiles') cr = db.cursor() q = 'select count(*) from scripts' cr.execute(q) r = cr.fetchone() n = int(r[0]) print 'the number of scripts : %d' % n