import pickle
import re


def load_dict(fname, var_names, load_func=pickle.load):
    """ Loads specific keys from a dictionary that was to a file
    :type fname: file name
    :type var_names: variables to retrieve. Can be a list or comma seperated string
          e.g. 'a, b,c' or ['a', 'b', 'c']
    :param load_func: default: pickle.load
    """
    if type(var_names) == str:
        var_names = re.split(', ?[, ]?', var_names)
    with open(fname, "rb") as f:
        data_dict = load_func(f)
    assert isinstance(data_dict, dict)
    return tuple([data_dict[var] for var in var_names])