Can';t从python 3.4.2脚本访问sqlite3数据库

Can';t从python 3.4.2脚本访问sqlite3数据库,python,database,sqlite,python-3.4,Python,Database,Sqlite,Python 3.4,我正在尝试使用python 3.4.2编写一个名为“播客”的sqlite3数据库。我创建了两个文件: 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

我正在尝试使用python 3.4.2编写一个名为“播客”的sqlite3数据库。我创建了两个文件:

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()
当我为dbcreate.py运行模块时,它像应该的那样打印了“tablecreated”。但是当我为dbinsert.py运行模块时,没有得到任何输出。于是我在Macbook Air上转到命令行,当我进入python3.4 shell并想从命令行访问这两个文件时,我得到:

>>> dbcreate.py
Traceback (most recent call last):
  File "stdin", line 1, in module
NameError: name 'dbcreate' is not defined
以及:

当我试图通过在命令行中键入.databases从sqlite3访问数据库时,我得到:


我不知道如何访问我在dbinsert.py中创建的数据库,因此如果您能给我任何帮助,我将不胜感激。多谢各位

您正试图从Python shell中运行
.py
文件,这将不起作用。而是从命令行运行

python3 dbcreate.py
python3 dbinsert.py
假设
python3
指向您的python3.4.2安装。这将执行您的代码,创建
.db
文件并插入您指定的值


dbinsert.py
没有输出,因为您没有打印任何内容,只是执行数据库命令。

有关如何从Python内部运行Python脚本,请参阅。Windows控制台允许复制/粘贴文本。你期望得到什么样的输出?我正在使用Macbook(苹果)的命令行。我期望的输出是我在conn.execute行中输入的值:“Invisibilia”、“NPR”、“Lulu Miller and Alix Spiegel”、“Hanselminutes”、“independent”和“Scott Hanselman”。为什么要尝试在sqlite3 shell中打开Python脚本?我得到了/Library/Frameworks/Python.framework/Versions/3.4/Resources/Python.app/Contents/MacOS/Python:无法打开文件“dbcreate.py”:[Errno 2]没有此类文件或directory@user907您是否在文件所在的目录中?您是对的,dbinsert.py中没有输出。我访问了正确的目录。
python3 dbcreate.py
python3 dbinsert.py