0

我可以将一堆空列表声明为:

a,b,c = [],[],[]

或者

a,b,c = [0]*16,[0]*8,[0,1,2]

有没有更简洁的方法来声明一堆列表?

(我还使用了列表推导和专门的类来做到这一点,我只是在寻找一种更简洁的方法。)

编辑:

这是对一个用例的简化解释:在 Verilog 中,我可能会执行以下操作:

wire [31:0] a, b, c, d, e;

或者

input [7:0] in1, in2, ETC。

在 C++ 中,我可以使用类 Wire 的实例对此进行建模,例如:

Wire32 a, b, c;

在 Python 中,如果我要使用类方法,一种方法可能是:

    a = Wire32() 
    b = Wire32() 
    c = Wire32() 

这对我来说似乎有点冗长。当通过 MyHDL 块时,它变得更加复杂。不过,我希望这可能是对可能导致相关创造性解决方案的用例的合理简化。

我目前的解决方案是:

a,b,c = [Wire(32) for i in range(3) ]

我不喜欢这个解决方案的一些事情:

1.  I have to count the number of elements which is cumbersome and error-prone
2.  The definition is after the list which is unfamiliar to the "customer" who will likely be a hw engineer familiar with Verilog
4

0 回答 0