A recipe to find out which function is the caller of the current function.
1 | import inspect |
Return a new partial object which when called will behave like func
called with the positional arguments args and keyword arguments keywords. If
more arguments are supplied to the call, they are appended to args. If
additional keyword arguments are supplied, they extend and override keywords.
Roughly equivalent to:
def partial(func, *args, **keywords):
def newfunc(*fargs, **fkeywords):
newkeywords = keywords.copy()
newkeywords.update(fkeywords)
return func(*(args + fargs), **newkeywords)
newfunc.func = func
newfunc.args = args
newfunc.keywords = keywords
return newfunc
This is a convenience function for invoking partial(update_wrapper,
wrapped=wrapped, assigned=assigned, updated=updated) as a function decorator
when defining a wrapper function. For example:
>>> from functools import wraps
>>> def my_decorator(f):
... @wraps(f)
... def wrapper(*args, **kwds):
... print('Calling decorated function')
... return f(*args, **kwds)
... return wrapper
...
>>> @my_decorator
... def example():
... """Docstring"""
... print('Called example function')
...
>>> example()
Calling decorated function
Called example function
>>> example.__name__
'example'
>>> example.__doc__
'Docstring'
Return a callable object that fetches item from its operand using the
operand’s __getitem__() method. If multiple items are specified,
returns a tuple of lookup values. Equivalent to:
def itemgetter(*items):
if len(items) == 1:
item = items[0]
def g(obj):
return obj[item]
else:
def g(obj):
return tuple(obj[item] for item in items)
return g
A recipe to find out which function is the caller of the current function.
1 | import inspect |
Diigo is about better ways to research, share and collaborate on information. Learn more »
Join Diigo