convert non-delimited to delimited

2007-08-27 Thread RyanL
I'm a newbie!  I have a non-delimited data file that I'd like to
convert to delimited.

Example...
Line in non-delimited file:
01397256359210100534+42050-102800FM-15+1198KAIA

Should be:
0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA

What is the best way to go about this?  I've looked all over for
examples, help, suggestions, but have not found much.  CSV module
doesn't seem to do exactly what I want.  Maybe I'm just missing
something or not using the correct terminology in my searches.  Any
assistance is greatly appreaciated!  Using Python 2.4

-- 
http://mail.python.org/mailman/listinfo/python-list


remove header line when reading/writing files

2007-10-11 Thread RyanL
I'm a newbie with a large number of data files in multiple
directories.  I want to uncompress, read, and copy the contents of
each file into one master data file.  The code below seems to be doing
this perfectly.  The problem is each of the data files has a header
row in the first line, which I do not want in the master file.  How
can I skip that first line when writing to the master file?  Any help
is much appreciated.  Thank you.

import os
import sys
import glob
import gzip
zipdir = "G:/Research/Data/"
outfilename = "G:/Research/Data/master_data.txt"
outfile = open(outfilename,'w')
os.chdir(zipdir)
dirlist = os.listdir(os.curdir)
for item in dirlist:
if os.path.isdir(item):
os.chdir(item)
filelist = glob.glob("*.gz")
for zipfile in filelist:
filein = gzip.GzipFile(zipfile,'r')
filecontent = filein.read()
filein.close()
outfile.write(filecontent)
os.chdir(os.pardir)
outfile.close()

-- 
http://mail.python.org/mailman/listinfo/python-list