Hi,
I want to add a certain number of 0s to the input, but I don??t know the 
specific number of 0s. I wrote a python block to complete this work, but I 
don??t seem to understand how the Python block works, which causes it to not 
work properly. code show as below:


class...
        self.k = k
        self.total = 0
    def work(self, input_items, output_items):
        in0 = input_items[0]
        out = output_items[0]
        in0_len = len(in0)
        self.total = self.total + in0_len
        i = 0
&nbsp; &nbsp; &nbsp; &nbsp; while i<in0_len:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out[i] = in0[i]
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i=i+1
&nbsp; &nbsp; &nbsp; &nbsp; if in0_len < len(output_items[0]):#I found that 
this sentence does not work. My previous understanding is that each 
"input_items" and "output_items" has a fixed value (4096). I need to determine 
that the input item has ended, and then enter the following operation
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remainder1 = self.total % self.k
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if remainder1 != 0:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while True:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out = 
np.append(out, 0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.total =self.total+1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
remainder2 = self.total % self.k
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = i+1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
i==len(output_items[0]) or remainder2==0:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; break
&nbsp; &nbsp; &nbsp; &nbsp; return len(output_items[0])

I think my problem is that this is a synchronized block, the number of input 
and output is the same, so it is never possible to enter the "if" statement, 
but I don't know what mechanism should I use to make the number of input and 
output inconsistent, "interpolation block "The output is a multiple of the 
input, and it cannot be used by me. How can I solve this problem, thank you in 
advance??
Best Regards,
linge93

Reply via email to