473,513 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing text file data to sqlite3

ryno du preez
91 New Member
Hi all I'm new to Python (just finnished training books)
I have a txt file with lines of data No Make and price
exp. (1 BMW 20000).
Now i want to import or copy this data to sqlite database.
I can get python to read the data and display it but doesn't copy it accross and also there is know errors.

Expand|Select|Wrap|Line Numbers
  1. import os
  2. import sys
  3. import sqlite3 as lite
  4.  
  5. #*car = open('C:/Users/rynod/Desktop/car.txt','r')
  6. #car2 = car.read()
  7.  
  8.  
  9. for car in open('C:/Users/rynod/Desktop/car.txt'):
  10.       car2 = car.split()
  11.       count = 0
  12.  
  13.       for i in (car2):
  14.           if '1' in i:
  15.               print(car2)
  16.  
  17.  
  18.  
  19.  
  20. #Create Database
  21. con = lite.connect('C:/db/test.db')
  22.  
  23. with con:
  24.  
  25.     cur = con.cursor()
  26.  #   cur.execute("INSERT INTO Cars VALUES(1,'Audi',57127)")
  27.     cur.execute("DROP TABLE IF EXISTS Cars")
  28.     cur.execute("CREATE TABLE Cars(Id INT, Name TEXT, Price INT)")
  29.  
  30.     cur.executemany("INSERT INTO Cars(Id, Name, Price) Values(?, ?, ?);",car2)
  31.     con.commit()
  32.  
Oct 2 '13 #1
0 1492

Sign in to post your reply or Sign up for a free account.

Similar topics

3
17783
by: Tomo | last post by:
I'm trying to import text file into some oracle table. I created control file, and text file, create table ..and run sqlldr80 from command promt.. Imort was not succesfull..error...
1
4300
by: redneck_kiwi | last post by:
I am attempting to import data from a text file. There are many records to be imported and the raw file format is: "1 |010-5502-502 |16H1-7-3 |CONTACT, ELECTRICAL, 7/8in. ...
10
2939
by: hendafe | last post by:
I have a problem of importing a text file into Access. The text file will be imported using a delimiter, say ( , ) for example. This should be imported into the database. An example is: John,...
3
2445
by: ghadley_00 | last post by:
Hi, I have a MS access database into which I need to import a text file that is oriented vertically (fields are listed from top to bottom with the value for each field appearing to the right of...
1
1621
by: lled | last post by:
I have a text file which I import on a daily basis - it goes into the same table, is set up exactly the same each time. The only thing that is different is the file name. Is there anything more...
2
6743
by: narpet | last post by:
Hello all, I'm still learning about c# and I have a major function that I need to write (in a forms application), and I have no idea how to go about it. Here's the scenario: I have a text file...
3
5101
by: gulllet | last post by:
I try to import a tab separated text file into sql server 2005 using the import guide. But when running the job I get the error message Error 0xc02020c5: Data Flow Task: Data conversion failed...
1
3480
by: nathanangula | last post by:
Hi All I am currently trying to import data from a text file to a table in Access and dont seem to have much idea of how I can do it. I have a little background of VB6 but I am not very...
1
1149
by: dpactrum | last post by:
Hello, I'm trying to import a text file with one column on it onto a table with 2 column on it, first column on the table is for my ID. I ignore the first column but it didn't accept the data? ...
1
114818
by: kallem | last post by:
Hi I have one text file generated using SQLServer 2005. While I am importing the text file into one of my PostgreSQL table using "copy" it is giving me the following error: ERROR: invalid...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.