我想做一些有点奇怪的事情。我希望能够访问可以作为非函数或函数访问的类属性:
class foo(object):
def __init__(self):
self.x = 99
def x(self, *args, **kwargs ):
print "x was called, args=%r, kwargs=%r" % (args, kwargs)
return( self.x ) # return something useful here...
f = foo()
print f.x # prints "x was called", 99
print f.x() # prints "x was called", 99