Discuss / Python / 不太理解path="有什么意义,有大佬帮忙讲解下吗

不太理解path="有什么意义,有大佬帮忙讲解下吗

Topic source

A22B9S

#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

    __repr__ = __str__

Floating

#2 Created at ... [Delete] [Delete and Lock User]

调用 `Chain().status` 时把 `_path` 初始化为 `"/status"`, 再一次加上 user、timeline、list, 最后打印时调用 `__str__`

.

#3 Created at ... [Delete] [Delete and Lock User]

path=''这个是为了传入一个固定值,以免用户/你自己没有传参的时候报错。


  • 1

Reply