在编辑器中的 sqlite3 中创建表时出错 [英] Error with create tables in sqlite3 in editor

查看:35
本文介绍了在编辑器中的 sqlite3 中创建表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的数据库中创建表.我也在该表中插入值.所以我在终端中运行 .py 文件,它没有打印插入的值.它在 shell 中工作,但在编辑器中却没有?我正在编写此代码来创建表:

I am creating table in my database. I am also inserting values into that table. So I am running the .py file in terminal it is not printing the inserted values. Its working in shell but with editor it doesn't ? I am writing this code to create table:

import sqlite3

conn = sqlite3.connect('raman.db')

c = conn.cursor()

c.execute("CREATE table raman(ATOMIC NUMBER INT, SYMBOL TEXT, ROW INT , COLUMN INT)")

c.execute("INSERT INTO raman VALUES(1,'H',1,'1')");  

conn.commit()

现在如果我想打印那些插入的值,它在编辑器中不起作用.但是使用外壳可以正常工作.我正在写这个来打印:

Now if i want to print those inserted values it doesn't work in editor. but with shell its working. i am writing this to print :

import sqlite3

conn = sqlite3.connect('raman.db')

c = conn.cursor()  

for row in c.execute('SELECT * FROM raman'):

       conn.commit() 

推荐答案

python 命令行 shell 会打印出您输入的所有内容的值,但这仅用于调试.

The python command-line shell prints out the value of everything you enter, but that is just intended for debugging.

要实际打印某些内容,请使用 print:

To actually print something, use print:

for row in c.execute('SELECT * FROM raman'):
    print row

(并且您可能希望从行中提取四个值并对其进行不同的格式设置.)

(And you might want to extract the four values from the row and format them differently.)

这篇关于在编辑器中的 sqlite3 中创建表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆