Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
console session - finding attributes that belong to function only, not inherited by object.
def g(x):
return x*x
g
<function g at 0x000000000306A268>
type(g)
<class 'function'>
dir(g)
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
def f(x):
return x
function_attrs = set(dir(f))
object_attrs = set(dir(object))
function_attrs -= object_attrs
from pprint import pprint
pprint(sorted(function_attrs))
['__annotations__',
'__call__',
'__closure__',
'__code__',
'__defaults__',
'__dict__',
'__get__',
'__globals__',
'__kwdefaults__',
'__module__',
'__name__',
'__qualname__']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.