473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading a delimited text file

2 New Member
Hello All,

I'm new for Python programming and I'm having some issues parsing a delimited text file. Any help, suggestions and advice is really appreciated. Thanks a lot in advance.

Objective

My input file could be .txt or .dat or .csv
Any kind of delimited file with the following delimiters (',','/','|',';',':')
  1. Make sure the files have a header
  2. File can have only 1, 2 or 6 columns. Any other number of columns makes it an invalid file
  3. Some column entries will have , in it. It should not clash with delimiter when the delimiter used is a ,
.

I want to use use sniff() to return the Dialect. How do I retrive the columns using CSV and make sure it has header and not just direct data.

regards
YesVee
Mar 25 '08 #1
1 2212
Subsciber123
87 New Member
Here is a place to start. See if you can get anything working from here:
Expand|Select|Wrap|Line Numbers
  1. import csv
Yes, there is a module for reading and writing csv files. You can choose the delimiter in there.
Apr 11 '08 #2

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

Similar topics

14
4490
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most recent entries. When I read line using StreamReader object it starts from the top, so looping though lines and keeping track of the line is not...
2
10674
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" & "Extended...
3
7024
by: Ben | last post by:
Hi all - I am having a bit of trouble and thought maybe someone in this group could shed some light. Here's the skinny... I am creating an automated process to import a bunch of text files into Access. I want to avoid creating a separate "Spec" for each file (there are over 180 files) and instead want to code my own dynamic importing...
5
15141
by: Christine | last post by:
I have code right now that reads in the file into an arraylist, but it reads in each line of the text file as a single element rather than the separate tab delimited strings in the line. Is there some way to split the text as its being read in? The file is both tab delimited and has a carriage return at the end of each line. Thanks! using...
1
2397
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development server.
8
3188
by: stephane8 | last post by:
I'm able to open and read my .csv file. But when the character "-" is in one of my fields (ex : 18802-002) I get a system.DBNull value ! Even if I edit the file with notepad and put "18802-002" I still get a DBNull value... I'm not able to figure this one out, any help would be appreciated. Here's my code : Dim ConnectionString As String...
6
22507
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn1x As New OleDb.OleDbConnection(ConStr) Dim dax1 As New OleDbDataAdapter("Select * from...
1
7802
jwwicks
by: jwwicks | last post by:
Hello All, This is a student assignment. So I don't want the complete answer just a hint or maybe a bumb on the head cause I'm doing it the wrong way. Assume I haven't done anything braindead like not include a header etc... I can post the whole code if you like/need it but I'm trying to spare the forum :) Got a product structure... ...
2
5017
by: tshad | last post by:
I have a program that is reading a csv file into a dataset. I want it to read the 1st line as data. But it ignores it. I have the Connection set up as: OleDbConnection csvConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvPath + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"");
0
7895
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
7826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8182
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
7935
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...
1
5701
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
5374
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
3818
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...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2333
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

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.