I have a file containing data like below:
88_NPDJ 565 789 3434 54454
98HGJDN 945 453 3453 23423
...
...
...
whats the best way to add headers to the file? After data has been entered into the file. The data is tab delimited.
Best way to get the effect of altering a file in place
is with fileinput:
import fileinput
headers = 'a b c d e'.split()
for line in fileinput.input(['thefile.blah'], inplace=True):
if fileinput.isfirstline():
print '\t'.join(headers)
print line,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With