• import csv
    callsign = input("Please enter the callsign: ")
    with open('stations.csv', 'r') as f:
        # usually see it recommended to use `with` when using open
        # not super important and won't bite you unless you're using
        # a different python implementation but it is good practice
        stations = csv.reader(f)
    
    # make a flag so you know if you find it
    found_station = False
    for row in stations:
        if callsign == row[0]:
            # try using format strings when combining strings
            # you can also use tuple unpacking, which is pretty neat
            # below is the same as
            # print ("{} = {}".format(row[0], row[1]))
            # or 
            # print (row[0] + " = " + row[1]) )
            print ("{0} = {1}".format(*row))
            # update our flag
            found_station = True
            # terminate loop early so we don't check rest of list
            break
    # check our flag to see if we managed to find what we wanted
    if not found_station:
        print("Station '{}' not found".format(callsign))
    

    Bit of reading:
    with statement
    format string
    tuple unpacking

    you could also use a "for-else" loop, but I don't know many people who use them so they just end up looking weeeeeeeird

    import csv
    call_sign = input("Please enter the callsign: ")
    with open('stations.csv', 'r') as f:
        stations = csv.reader(f)
    
    for row in stations:
        if call_sign == row[0]:
            print ("{0} = {1}".format(*row))
            break
    else:
        print("Station '{}' not found".format(callsign))
    
  • Thanks, but I get errors in both :(

    Please enter the callsign: A30
    Traceback (most recent call last):
    File "stations.py", line 10, in

    for row in stations:
    

    ValueError: I/O operation on closed file.

    Please enter the callsign: A30
    Traceback (most recent call last):
    File "stations.py", line 5, in

    for row in stations:
    

    ValueError: I/O operation on closed file.

About