import glob
import pickle


def load_nets(myglob):
    """
    Load a dictionary of trained neural networks with filenames
    matching a unix-style pattern.  Filenames of networks trained for
    individual output measures should be named,
    `final-OutputCol-NameOfOutputCol_net.pkl` and filenames for a network
    trained for the complete set of output measures should be `full_net.pkl`.

    Parameters
    ----------
    myglob  : str
              the unix-style pattern (including abs or rel path) for the
              filenames you want to load.  Wildcards accepted.

    Returns
    -------
    nets  : dict
            a dictionary with the trained networks.  Keys are the columns
            from y_train that the network is trained on.
    """
    files_list = glob.glob(myglob)
    nets = {}

    if [x for x in files_list if 'full' in x]:
        with open(files_list[0], 'rb') as pkl:
            nets['all'] = pickle.load(pkl)[0]
    else:
        for filename in files_list:
            output_col = int(filename.split('/')[-1].split('-')[1])
            with open(filename, 'rb') as pkl:
                nets[output_col] = pickle.load(pkl)[0]

    return nets