I'm running in circes trying to accomplish something very simple. I have a csv file with multiple lines resembling:
0002345, 24, 5, 0.24
I need this format in my output file:
'0002345', 24, 5 0.24
The first entry is a census meshblock code and the leading zeros are relevant for comparison purposes. After extensive googling, I have found half a dozen different ways to convert 0002345 into a string, all of which work brilliantly at the prompt. However, when thrown into a for loop, the csv I get always returns the item without the 'quotes'.
Here's the fourth version that works at the prompt but not in my loop:
wf1 = open('meshoutE.txt', 'w') #output file handle writer1 = csv.writer(wf1) for entry in rf1: entry = str(entry).zfill(7) writer1.writerow(entry) wf1.close()
I've tried many variations on the theme without success, in both 2.6 and 3.1. I cannot seem to get the quotes into the output. I am clearly missing the forest for the trees! Anyone got an ax?