473,587 Members | 2,527 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 1494

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

Similar topics

3
17803
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 occurs..sql*loader-524:partial record found at end of data file (proba.ctl) See what i done, and please help me.. CREATING TABLE ******************* create tabale...
1
4305
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. |356.0000 |0.0000" "1 |03-06-1062 |16H3-5-1 |RECEPTACLE,FREE HANGING 6 CON.|1.0000 |0.0000" "1 ...
10
2953
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, is, a, boy Ada, is, a, girl I have tried using the DoCmd.TransferText but I am not getting results.
3
2457
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 the field name (with a "|" as a delimiter)). The text file will only have 1 record's data. I would ideally like to setup a linked table to import...
1
1629
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 automatic I can set up to help with the import of this file? Sometimes I might leave it for a few days so will have a few to put in. Trev.
2
6748
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 that contains all the data needed for a database table (MS SQL Server). I know the location and length of each field within the text file. Can...
3
5128
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 while converting column "Column 19" (67) to column "Column 19" (404). The conversion returned status value 2 and status text "The value could not be...
1
3490
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 familiar with VBA for Access. Well, where do I start in writting the code for importin/exporting data to/from Access tables and what are the important...
1
1153
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? Needs help
1
114823
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 byte sequence for encoding "UTF8": 0xff Can any one tell me what i need to do get the data from SQLServer 2005 to PostgreSQL?
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
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 we have to send another system
0
1189
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.