您好我是新来的Python和经历了一些教程,我的代码不给任何错误,但它失败,出现问题的完整列表是在底部SQLite的INSERT INTO失败
这是我第一次的.py文件,该文件是rehber.py
import crehber
print("ASIM's Contact List")
print("To create a Table press 1")
print("To write into database press 2")
choice = int(input("Your Choice: "))
def checkInput(choice):
if choice == 1:
print("Your Choice is ", choice)
crehber.tablecreate()
return True
elif choice == 2:
print("Your Choice is ", choice)
name = str(input("Enter name: "))
surname = str(input("Enter surname: "))
number = int(input("Enter number: "))
crehber.tableInsert(name,surname,number)
return True
else:
print("Invalid choice, please re-enter")
while checkInput(choice) != True:
choice = int(input("Your Choice: "))
,这里是另一个.py文件是crehber.py
import sqlite3 as db
def tablecreate():
conn = db.connect('rehber.db')
cursor = conn.cursor()
cursor.execute('create table bilgiler(name text,sname text, num text)')
print("Table is created")
def tableInsert(name,surname,number):
conn = db.connect('rehber.db')
cursor = conn.cursor()
cursor.execute('insert into bilgiler(name,sname,num) values(?,?,?)', (name,surname,number))
print("Insert is Successful")
conn.close()
附加信息:
1)SQLite是在C:\ sqlite的 2-)我创建了一个目录c:\ pythonb一起玩,这是我的.py文件是
问题列表&问题:
1 - 在sqlite目录中,并输入sqlite3 rehber.db时,该文件在那里创建。 然后当我运行该程序,并调用
tableCreate() function
rehber.db出现在pythonb目录,这正常吗?
2-当我做一些条目,并得到“插入成功”的消息 我去sqlite目录并输入sqlite3 rehber.db 然后选择* from bilgiler; 但是什么都没有出现..你认为什么是错的?
3-我有时会错过分号;在select命令和我卡在sqlite shell后,如何退出而不关闭commandprompt?
感谢节约您的时间在阅读,任何帮助表示赞赏
当我在pythonb中运行rehber.db时,我没有得到任何输出..我应该将rehber.db从sqlite目录复制到pythonb目录然后运行程序? – Licentia 2014-09-06 06:49:20