Discuss / Python / 加了一个__call__定义

加了一个__call__定义

Topic source

執謎卜誤

#1 Created at ... [Delete] [Delete and Lock User]
class Chain(object):
    def __init__(self, path=''):
        self._path = path
    def __getattr__(self, path):
        return Chain('%s/%s' % (self._path, path))
    def __str__(self):
        return self._path
    def __call__(self, username):
        return Chain('%s/%s' % (self._path, username))        
    __repr__ = __str__

  • 1

Reply