Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python xlwings'的方法如何工作;s类应用程序,当它使用repr(list(self))时_Python_Python 3.x_Xlwings - Fatal编程技术网

Python xlwings'的方法如何工作;s类应用程序,当它使用repr(list(self))时

Python xlwings'的方法如何工作;s类应用程序,当它使用repr(list(self))时,python,python-3.x,xlwings,Python,Python 3.x,Xlwings,我试图创建一个新类,在模块xlwings中发现了一个类似的类,但我不理解方法repr在调用self(“repr(list(self))时是如何工作的。该类如何知道使用apss返回列表的 代码是: class Apps(object): def __init__(self, impl): self.impl = impl def __call__(self, i): return self[i-1] def __repr__(se

我试图创建一个新类,在模块xlwings中发现了一个类似的类,但我不理解方法repr在调用self(“repr(list(self))时是如何工作的。该类如何知道使用apss返回列表的

代码是:

class Apps(object):    
    def __init__(self, impl):
        self.impl = impl

    def __call__(self, i):
        return self[i-1]

    def __repr__(self):
        return '{}({})'.format(
            self.__class__.__name__,
            repr(list(self))
        )

    def __getitem__(self, item):
        return App(impl=self.impl[item])

    def __len__(self):
        return len(self.impl)

    def __iter__(self):
        for app in self.impl:
            yield App(impl=app)

list
调用
\uuuu iter\uuuu
所以它在调用
App的App对象列表上调用
repr
。\uuuuu repr\uuuuu
对于每个项目。

对于
\uu call\uuuuu
的内容,谢谢。@rvcristiand
\uu call uuuu
将在像函数一样调用应用实例时调用。将对self c进行索引所有
\uuu getitem\uuu
将返回i-1项目的应用程序实例。