def getAircraftCodeDict():
    """
    A function to read in a database and create a dictionary with the
    key coming from the first column.  The dictionary value an Aircraft() object.
    
    The dictionary is returned.
    
    Each row of the database table contains 1 integer and 1 string in double quotes.
    """
    table = 'aircraft'
    connection = openConnection()
    curs = connection.cursor()
    sqlcmd = "SELECT * FROM " + table
    d = {}

    curs.execute(sqlcmd)
    for row in curs.fetchall():
        aircraft = airlineClasses.Aircraft()
        aircraft.aircraftCode = row[0]
        aircraft.name = row[1]
        d[aircraft.aircraftCode] = aircraft

    curs.close()
    connection.close()
    return d
def getAircraftCodeDict():
     
    filename = 'C:/Course/1905/Data/aircraft.csv'
    dictionary = {}
    for input in open(filename,'r'):
        if input:
            input = input.rstrip()               # remove the newline
            input = input.replace('"','')        # replace double quotes with null
            input = input.split(',')             # split at the comma      
            aircraft = airlineClasses.Aircraft(aircraftCode = int(input[0]), name= input[1])    # create new object
            dictionary[aircraft.aircraftCode] = aircraft  # store in dictionary
    return dictionary
예제 #3
0
def getAircraftCodeDict():

    dictionary = {}
    for input in open(filename2, 'r'):
        if input:
            input = input.rstrip()  # remove the newline
            input = input.replace('"', '')  # replace double quotes with null
            input = input.split(',')  # split at the comma
            aircraft = airlineClasses.Aircraft()  # create new object
            aircraft.aircraftCode = int(input[0])  # assign into new object
            aircraft.name = input[1]
            dictionary[aircraft.aircraftCode] = aircraft  # store in dictionary
    return dictionary