[Tutor] An interesting case... of east vs. west

Alan Gauld alan.gauld at btinternet.com
Wed Jul 11 01:21:08 CEST 2007


"John" <washakie at gmail.com> wrote 

> you can see what my problem was:
>
> for i in range(0,344)
>     y=d[i][2].split('\xb0')
>     x=d[i][3].split('\xb0')
> ...
>     declon=int(xdeg)+(float(xmin)/60)

The first thing I'd suggest is not to try to do it all in one step.
Break it into chunks and write helper functions for each part, 
that will be much easier to debug.

I think you want a parser to extract the lat and lon values 
as a tuple. A function to tidy up the lat and another to do 
the lons. Finally a ms to decimal convertor.

Your top loop then becomes:

coords = []
for line in file(...):
    lat,lon = getLatLon(line)
    lat = latTidy()
    lon = lonTidy()
    coords.append((asDec(lat),asDec(lon)))


To produce a list of coord tuples in decimal format.

Now, can you solve the 4 sub problems?

A regex may help with the first one.
The second and third will need knowlege of each possible 
format
The fourth is a straightforward math exercise

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list