reader = csv.reader(open('new_mondy_csc_data_revise.csv'), delimiter=',', quotechar='"')
header = tuple(reader.next())
print "%-14s|%-10s|%-5s|%-5s|%-11s|%-11s|%-11s|%-11s|%-11s|%3s" % header # read header line from csv
print "-" * 45

There are a total of 10 fields in the header across a csv file
I want to print the first three instead, how can I do that?

Recommended Answers

All 2 Replies

print "%-14s|%-10s|%-5s" % header[:3]

BTW
Your comment is not accurate. The header is already read in that line.

print "%-14s|%-10s|%-5s" % header[:3]

BTW
Your comment is not accurate. The header is already read in that line.

Oh thank you. Yeah, they will be fix once everything is finsih
Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.