Accessing function as attribute in a Python class Accessing function as attribute in a Python class python python

Accessing function as attribute in a Python class


You can use the @property decorator.

class foo(object):    bar = "bar"    @property    def baz(self):        return "baz"


Take a look at the decorator form of property.

@propertydef baz(self):  return "baz"