sqlite - Python Sqlite3- Python shell can create and edit databases but why can't a .py file create or access any database -
import sqlite3 db=sqlite3.connect('new.db') cursor=db.cursor() cursor.execute('''create table hello(id integer primary key, message_type, time_sent, time_received, response)''')
the above program when executed python shell execute , create database said name when run same program .py file,it won't create table or database
import sqlite3 os.path import expanduser db_dir = expanduser("~") db=sqlite3.connect(db_dir+'/new.db') cursor=db.cursor() cursor.execute('''create table hello(id integer primary key, message_type, time_sent, time_received, response)''')
now in home directory new.db
Comments
Post a Comment