def getitem(value, key, *default):
    """
    gets an item, like getattr
    
    :Example:
    ---------
    >>> a = dict(a = 1)
    >>> assert getitem(a, 'a') == 1
    >>> assert getitem(a, 'b', 2) == 2
    
    >>> import pytest
    >>> with pytest.raises(KeyError):
    >>>     getitem(a, 'b') 

    """    
    if len(default):
        try:
            return value[key]
        except Exception:
            return default[0]
    else:
        return value[key]