All pastes #770940 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-11-12 18:34 UTC
rendered paste body
from picture import * 

class format_float (float):
    '''This class recompiles floats so that it shows 2 digits behind the 
    decimal'''
    def __repr__(n):
        result = str (n) [0:8]
        if result == 0.0:
            result = float('%08g'%result)
        return result

def read_file (f):   
    ''' This function will read a text file containing airport information
    then strip unwanted characters and send data to read_airport function
    for processing'''
    
    for line in f:
        yield line.rstrip().split(":")
        
def read_airports(file):
    '''This function will read in data submitted by read_file function, compile
    the data, and return 2 lists which one contains the each airport longitude
    and lattitude and the other containing airport with non-domestic status'''
    
    lat, long, location, status= '','',{}, {}
    for x in read_file(file):
        lat = float(str(x[3]) + "." + str(x[4]) + str(x[5]))
        long = float(str(x[6]) + "." + str(x[7]) + str(x[8]))
        location [x[0]] = (format_float(lat), format_float(long))
        if len(x) == 10:
            status [x[0]] = x[9]
    return  location, status

file = open(pick_a_file())
print read_airports(file)

####################THE FILE BELOW####################
HKI:HONG KONG INTERNATIONAL:HONG KONG:00:00:00:00:00:00:INT
PIA:PEARSON INTERNATIONAL:CANADA:36:42:52:42:88:26:INT
DA:DUBLIN AIPORT:DUBLIN:99:99:99:99:99:99