ScottChang25

ArcGIS10.0-PythonWindow:Reformatt txt data in-line:Runtime error-invalid literal for

Discussion created by ScottChang25 on Nov 7, 2012
Latest reply on Nov 7, 2012 by posthumusb
Hi all,
I executed the following code on the attached txt file:
>>> # open the text file, read it into memory
... file = open('c:/testing/lat-lon-date-conversions.txt').read().splitlines()
... # define a new, empty list object
... l = []
... # iterate through the lines of the file, slice up the line by index
... #   position of each data column
... for line in file:
...     v1 = line[0:8].strip()  # lat dms
...     v2 = v1[0:2]  # lat deg
...     v3 = v1[2:4]  # lat min
...     v4 = v1[4:6]+'.'+v1[6:8]  # lat sec
...     v5 = str(int(v2)+(float(v3)/60)+(float(v4)/3600))  # lat dd
...     v6 = line[8:17].strip()  # lon dms
...     v7 = v6[0:3]  # lon deg
...     v8 = v6[3:5]  # lon min
...     v9 = v6[5:7]+'.'+v6[7:9]  # lon sec
...     v10 = str('-'+str(int(v7)+(float(v8)/60)+float(v9)/3600))  # lon dd
...     v11 = line[17:21]  # date as MMYY
...     v12 = str(v11[0:2])+'/'+str(v11[2:4])  # concatenate date as MM/YY
...     # add our line to list l
...     # do string formatting to lat/long to display only 5 decimal points
...     l.extend([[('%.5f' % float(v5)),('%.5f' % float(v10)),v12]])
...     # print out each line to stdout
... for each in l:
...     print each
... 
Runtime error <type 'exceptions.ValueError'>: invalid literal for int() with base 10: ',09'
>>> 



I don't no ideas why I got: Runtime error <type 'exceptions.ValueError'>: invalid literal for int() with base 10: ',09'.
Please kindly help and advise.

Thanks,
Scott Chang

Outcomes