diff --git a/examples/python/bufr_encode_flight.py b/examples/python/bufr_encode_flight.py index 0491cb310..cc302f125 100644 --- a/examples/python/bufr_encode_flight.py +++ b/examples/python/bufr_encode_flight.py @@ -20,6 +20,13 @@ from eccodes import * VERBOSE = 1 # verbose error reporting +def parse_date(x): + return datetime.strptime(x.decode('ascii'), '%Y%m%d') + + +def parse_time(x): + return datetime.strptime(x.decode('ascii'), '%H:%M:%S') + def example(csvfile, input_filename, output_filename): fbufrin = open(input_filename, 'rb') @@ -29,8 +36,6 @@ def example(csvfile, input_filename, output_filename): # The first line in the CSV has the column names print('Reading input CSV file: ', csvfile) - parse_date = lambda x: datetime.strptime(x.decode('ascii'), '%Y%m%d') - parse_time = lambda x: datetime.strptime(x.decode('ascii'), '%H:%M:%S') data = np.genfromtxt(csvfile, delimiter=',', dtype=None, names=True, converters={0: parse_date, 1: parse_time}) @@ -87,6 +92,9 @@ def example(csvfile, input_filename, output_filename): codes_write(bufr, fbufrout) print('Created output BUFR file: ', output_filename) + fbufrin.close() + fbufrout.close() + def main(): if len(sys.argv) < 4: