newbie python query.
Using python 2.7.3
Trying the following code:
#Read in from a file
BNG = csv.reader(open('BNG.csv', 'rU'), delimiter = ',')
BNG.next()
#Get the output file ready
outputFile = open('BNGandLatLon.csv', 'wb')
output=csv.writer(outputFile,delimiter=',')
output.writerow(['Lat', 'Lon', 'E', 'N'])
#Loop through the data
for E,N in BNG:
lat, lon = OSGB36toWGS84(float(E), float(N))
output.writerow([str(lat), str(lon), str(E), str(N)])
#Close the output file
outputFile.close()
But it falls over at the iteration over BNG with:
ValueError: too many values to unpack
I've checked out this error (eg Iterate over a string 2 (or n) characters at a time in Python) and think it's to do with for E, N in BNG:
finding one item (E and N) instead of two separate E
and N
values. But I'm having real problems coding this up from the BNG.csv file. Have used .item
, zip
and izip
but haven't been able to get it right. Some help would be v welcome. Cheers