Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Accessing method as function object
#1
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.
Quote
#2
help(random.shuffle)
Quote
#3
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to mock an object that is created during function call? Schlangenversteher 0 129 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher
  function vs method prateekshaw 2 160 Nov-14-2019, 07:00 PM
Last Post: DeaD_EyE
  print all method and property of list object engmoh 4 362 Oct-26-2019, 05:33 PM
Last Post: engmoh
  I'm trying to figure out whether this is a method or function call 357mag 2 408 Jul-04-2019, 01:43 AM
Last Post: ichabod801
  'function' object has no attribute 'write' paramiko lateublegende 1 1,198 Feb-12-2019, 09:03 PM
Last Post: nilamo
  function method problems drchar 2 567 Dec-11-2018, 02:38 PM
Last Post: buran
  accessing globals from a function Skaperen 8 922 Sep-01-2018, 11:50 PM
Last Post: Skaperen
  Understanding Method/Function robdhunter 2 877 Mar-10-2018, 11:57 PM
Last Post: robdhunter
  Python-Function object creation studnik2 2 1,266 Jul-28-2017, 08:34 PM
Last Post: DeaD_EyE
  How to pass value from method to function iFunKtion 11 4,109 May-23-2017, 05:06 PM
Last Post: iFunKtion

Forum Jump:


Users browsing this thread: 1 Guest(s)