转至:http://30daydo.com/article/93
#判断表存不存在来创建表
def create_table(): conn = sqlite3.connect(db_name) try: create_tb_cmd=''' CREATE TABLE IF NOT EXISTS USER (NAME TEXT,AGE INT,SALARY REAL); ''' #主要就是上面的语句 conn.execute(create_tb_cmd) except: print "Create table Failed" return False insert_dt_cmd=''' INSERT INTO USER (NAME,AGE,SALARY) VALUES ("Rocky",10,20.1); ''' conn.execute(insert_dt_cmd) conn.commit() conn.close()