I am currently trying to read python codebase - I picked up the crayons by Kenneth Reitz as it seems very well written and rather simple, but I am having issues understanding the meaning of the following method (code ref):
...
def __getattr__(self, att):
def func_help(*args, **kwargs):
result = getattr(self.s, att)(*args, **kwargs)
try:
is_result_string = isinstance(result, basestring)
except NameError:
is_result_string = isinstance(result, str)
if is_result_string:
return self._new(result)
elif isinstance(result, list):
return [self._new(x) for x in result]
else:
return result
return func_help
...
While I have pretty good idea what the magic method __getattr__
does, I kind of struggle seeing the point of returning the function (or how would I use it for that matter).