Hello, I have 4 columns in CSV and I want to make the output for COL4 as next line.
CSV Columns
COL1 COL2 COL3 COL4
output:
<line1> Col2
<line2> Col3
<line3> Col4
thank you!
CSV Columns
COL1 COL2 COL3 COL4
output:
<line1> Col2
<line2> Col3
<line3> Col4
thank you!
#def pctUser():
jobnum = str(input("Enter Work Number: "))
jobnam1 = str(input("Type Project: "))
jobnam2 = str(input("Type Description: "))
# read file names into a list
en_dir = glob.glob('Job *.txt')
# prep for writing data file
with open('DF_' + jobnum + '.txt', 'w') as d:
# write data header line
d.write('REC\tCOL1\tCOL2\tCOL3\n')
rec = 1
# open data file
with open(en_dir[0]) as f:
fline = ' '
# read data
while fline != '':
fline = f.readline()
if fline == '':
break
# write <record number>, <work number>-<record number> and <data>
d.write(str(rec) + '\t' + str(jobnum) + '-' + str(rec) + '\t')
# write data line
d.write(fline)
# increment record counter
rec = rec + 1
nTotal = rec - 1
#prep for writing output file
with open('DV_' + jobnum + '.txt', 'w') as v:
# write dv header
v.write('Job No. ' + jobnum + ' (prepared by me)\n')
v.write(jobnam1 + '\n')
if jobnam2 != '':
v.write(jobnam2 + '\n')
v.write('\nTotal - ' + str(nTotal) + '\n\n')
v.write('Print file - D_' + jobnum + '.txt\n\n')
v.write('First 9 records + last record:\n\n')
rec = 1
# open data file again
with open(en_dir[0]) as f:
fline = ' '
# write 9 lines of output
while fline != '':
fline = f.readline()
if fline == '':
break
# write output lines
if rec < 10:
v.write(jobnum + '-' + str(rec) + '\n')
v.write(fline + '\n')
#changes
v.write()
if rec == nTotal:
v.write(jobnum + '-' + str(rec) + '\n')
v.write(fline)
# increment record counter
rec = rec + 1
