def getname(var):
    """
    Attempt to find the name of a variable from the main module namespace

    Parameters
    ----------
    var
        The variable in question

    Returns
    -------
    name : str
        Name of the variable
    """
    import __main__ as main_mod
    for name in dir(main_mod):
        val = getattr(main_mod, name)
        if val is var:
            return name
    return None
