I am trying to pass a function, which doesn't take any input and returns some value. The function is defined inside the class. However, it is throwing following error:
NameError: name 'self' is not defined Please see the sample code below:
class Test(): def rand(self): return 4 def print_rand(self, num=self.rand()): print num t = Test() print t.print_rand() Any workaround, please? Note that I am using Python 2.7 in on Ubuntu 14.04 LTS PC.
self.rand()