从实例数组中获取属性数组

时间:2019-03-01 13:06:49

标签: python arrays class

我有一个简单的类Foo,由:

class Foo:
    def __init__(self, bar: list):
        self.bar = bar

以及此类foos的实例实例的数组:

foos = []
foos.append(Foo(bar=[1, 2]))
foos.append(Foo(bar=[3, 4]))
foos.append(Foo(bar=[5, 6]))

我想要一个bars的数组,如下所示:

bars = [[1, 2], [3, 4], [5, 6]]

请问该如何处理?

1 个答案:

答案 0 :(得分:2)

您可以使用简单的list comprehension

PrintDocument pd = new PrintDocument();
CountdownEvent countdown = new CountdownEvent(this.PathsJPG.Length);
for (int i = 0; i < this.PathsJPG.Length; i++) {
    currentpath = getCurrentPath(i);
    pd.PrintPage += PrintPage;
    pd.EndPrint += (o,e) => { countdown.Signal(); }
    pd.Print();
}
countdown.Wait();