Python Forum
Accessing method as function object - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Accessing method as function object (/thread-24448.html)



Accessing method as function object - ClassicalSoul - Feb-14-2020

Hi,

How do you access a class method as a function object (not a function call)? The context is that I would like to use the help() function on random.shuffle(), but that results in an error because random.shuffle() prompts a function call, not the function itself.


RE: Accessing method as function object - buran - Feb-14-2020

help(random.shuffle)


RE: Accessing method as function object - wavic - Feb-14-2020

In [1]: class Foo:
   ...:     def __init__(self, num):
   ...:         self.num = num
   ...:     @property
   ...:     def double(self):
   ...:         return self.num + self.num
   ...:

In [2]: obj = Foo(5)

In [3]: obj.double
Out[3]: 10