Formatting question.
mike5160
mike5160 at gmail.com
Tue Nov 20 18:11:38 EST 2007
Hi all,
My input file looks like this : ( the data is separated by tabs )
11/26/2007 56.366 898.90 -10.086 23.11 1212.3
11/26/2007 52.25 897.6 -12.5 12.6 13333.5
11/26/2007 52.25 897.6 -12.5 12.6 133.5
The output I'm trying to get is as follows :
( Insert NBUSER.Grochamber Values
'11/26/2007','56.366','898.90','-10.086','23.11','1212.3', )
( Insert NBUSER.Grochamber Values
'11/26/2007','52.25','897.6','-12.5','12.6','13333.5', )
( Insert NBUSER.Grochamber Values
'11/26/2007','52.25','897.6','-12.5','12.6','133.5', )
The following is the program i have written so far :
LoL = []
for line in open('mydata.txt'):
LoL.append(line.split("\t"))
print "read from a file: ", LoL,
outfile = open("out.dat", "w")
lilength = len(LoL)
liwidelength = len(LoL[1])
print "length of list is " , lilength, "long"
print "length of list is " , liwidelength, "long"
for x in range(lilength):
outfile.write(" ( ")
outfile.write('Insert NBUSER.Grochamber Values ')
for y in range(liwidelength):
outfile.write( "'%s'," % (LoL[x][y]))
outfile.write(" ) \n")
outfile.close()
I have 3 questions :
1. The formatting in the first line comes out wrong all the time. I m
using windows python 2.5.1. The last part of the first line is always
on the second line.
2. How do I avoid the "," symbol after the last entry in the line?
(this are supposed to be sql-queries - importing excel based tabbed
data to sql database)
3. What do I do when the data is missing? Like missing data?
Thanks for all your help!
Mike
More information about the Python-list
mailing list