I am trying to write create a sqlite3 database using python 3.4.2 called "podcasts". I created two files:
dbcreate.py:
import sqlite3 as db
conn = db.connect('test.db')
cursor = conn.cursor()
cursor.execute("create table podcasts(name text, hosts text, channel text)")
print("table created")
dbinsert.py:
import sqlite3 as db
conn = db.connect('test.db')
cursor = conn.cursor()
cursor.execute('insert into podcasts values("Invisibilia","NPR", "Lulu Miller and Alix Spiegel")')
cursor.execute('insert into podcasts values("Hanselminutes", "independent", "Scott Hanselman")')
conn.commit()
conn.close()
When I ran the module for dbcreate.py, it printed "table created" like it should. But when I ran the module for dbinsert.py, I got no output. So I then went to the command line on my Macbook Air and when I entered the python3.4 shell and wanted to access both files from the command line, I got:
>>> dbcreate.py
Traceback (most recent call last):
File "stdin", line 1, in module
NameError: name 'dbcreate' is not defined
and:
>>> dbinsert.py
Traceback (most recent call last):
File "stdin", line 1, in module
NameError: name 'dbinsert' is not defined
When I tried accessing the database from sqlite3 in the command line by typing in .databases, I get:
I don't know how to access the database I created in dbinsert.py so I would appreciate any help you can give me. Thank you.