Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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() 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
140 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...