def from_file(infilename, key):
    """
    Read histogram written out by heppy (using :py:class:`heppy.basehistogram.to_file`).

    :param infilename: name of the file that the histogram should be read from
    :type infilename: :code:`str`
    :param key: name/key of the histogram inside the input file
    :type key: :code:`str`

    :returns: :py:class:`heppy.histogram1d` or :py:class:`heppy.histogram2d`
    """
    with open(infilename, 'r') as infile:
        sep = ' : '
        for line in infile:
            if line.split(sep)[0] == key:
                from numpy import array, nan, inf
                return eval(line.split(sep)[1])
        raise RuntimeError(
            'Could not find histogram key "{key}" in input file "{infilename}"'
            .format(key=key, infilename=infilename))
