J
Junior
I want to open a text file for reading and delineate it by comma. I also
want any data
surrounded by quotation marks that has a comma in it, not to count the
commas inside the
quotation marks
if the file testfile.txt contains the following;
5,Tuesday,"May is a spring month",Father's Day
1,Saturday,"June,July and August",Independance Day
and I write the following program
fname = open('testfile.txt', 'r')
ct=1
while ct != 3:
rd=(fname.readline())
filedata=rd.split(',')
print "var2=",filedata[2]
ct +=1
fname.close
filedata[2] will = "May is a spring month"; on the first pass and
filedata[2] will = "June; on the second pass
How do I get filedata[2] to = "June,July and August" on the second pass
and filedata[3] to = Independance Day
want any data
surrounded by quotation marks that has a comma in it, not to count the
commas inside the
quotation marks
if the file testfile.txt contains the following;
5,Tuesday,"May is a spring month",Father's Day
1,Saturday,"June,July and August",Independance Day
and I write the following program
fname = open('testfile.txt', 'r')
ct=1
while ct != 3:
rd=(fname.readline())
filedata=rd.split(',')
print "var2=",filedata[2]
ct +=1
fname.close
filedata[2] will = "May is a spring month"; on the first pass and
filedata[2] will = "June; on the second pass
How do I get filedata[2] to = "June,July and August" on the second pass
and filedata[3] to = Independance Day