importing .txt data into sqlite using python

Joined
Dec 17, 2008
Messages
1
Reaction score
0
Hi folks
i am facing this problem in my following codes where i am trying to create a database using pysqlite and load data from text file where data is arranged in this form "Birthday2|12/5/2008|HTC|this is my birthday"
but i could connect to the database, create it into my current working directory but i can't load the data from my text file in the same working directory into sqlite database created. please any idea or tips

thanks in advance

Code:
Codes

import os
import sqlite3
from pysqlite2 import dbapi2 as sqlite3

#Connecting to Database
connection = sqlite3.connect('Photos.db')
memoryConnection = sqlite3.connect(':memory:')
cursor = connection.cursor()
cursor.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))') 
#reading text file
text_file = open("/home/waseem/Project2/photos.txt", "r")
whole_thing = text_file.read()
print whole_thing
#writing text data into database
for row in text_file:
	cursor.execute('INSERT INTO photos VALUES(Name,Date,Make,Tag)', row)
#cursor.commit()
text_file.close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top