class Scalar(object):

    def __init__(self, val):
        self._val = val

def __getattr__(self, key):
    return Scalar(getattr(self._val, key, None))

def __call__(self, *args, **kwargs):
    return Scalar(self._val(*args, **kwargs))

def __str__(self):
    return 'Scalar(%s)' % self._val
s = Scalar('hi there')
s.upper()
s.a.b.c.d
Python - safe & elegant way to set a variable from function that may return None