import glob


def get_model_file_iterator(training_run, model_param_folder=None):
    """
    Get an iterator containing all files with model parameters in the run. Iterator is more memory efficient than list.

    :param training_run: String, the name of the training run during which the model params were saved
    :param model_param_folder: String, full path of the folder containing the model params.
    When None, a default location is used
    """
    if model_param_folder is None:
        model_param_folder = '/uio/hume/student-u31/eirikolb/tmp/logs/poet_{}/'.format(training_run)

    model_param_file_name = r'poet_*.best.json'
    model_param_file = model_param_folder + model_param_file_name

    return glob.iglob(model_param_file)