Newbie trying to nest instrumentation queries in array

Hi, gang,

This is my second week of Python - I’m trying.
I want to test a phono preamp stage at various frequencies, so I have an array named test_param where each row has 4 elements: the frequency for the signal generator, the time scale and input sensitivity for the oscilloscope, and a delay to account for 256 samples for an average reading.

That runs fine. Now I want to read the 'scope while the array is running. I tried indenting my read block, that doesn’t work. Is it possible to ‘nest’ a few commands to read and write the measurement while stepping through rows in an array?

Here is where I’d like to insert measurements, after the (delay):

for row in test_param:
    freq, time_scale, att, delay = row
    gen.write(f"C1:BSWV FRQ,{freq}")
    scope.write(f"HORIZONTAL:MAIN:SCALE {time_scale}")
    scope.write(f"CH1:SCALE {att}")
    time.sleep(delay)

Thanks!
Frank

It would be easier to help you if we would get a working reproducer and the desired output.
You are talking about an array is this really an array or a list.

Welcome to the forum!

Absolutely!.

For example, for simplicity, let’s assume that you want to print the following via a function every time it is looping:

def test_func():

    # Edit the body to include your commands here
    print('Called test function within loop.')


for row in test_param:

    freq, time_scale, att, delay = row

    gen.write(f"C1:BSWV FRQ,{freq}")
    scope.write(f"HORIZONTAL:MAIN:SCALE {time_scale}")
    scope.write(f"CH1:SCALE {att}")

    test_func()  # Called a simple print statement but you can include anything you want

    time.sleep(delay)

Hi, Paul,

Thank you. For generality, I could read or write instead of print, I’m guessing. Is the trick inserting a called function rather than the direct command in the loop?

Cheers,
Frank

Yes, you can include read or write commands instead of a print statement. I just included a print statement because you can visually see the result on your terminal for quick verification.

You can write your script as how you see fit. You can write the commands explicitly in the loop body or per a function call. It is very flexible.

Hi, sji,

Could you kindly rephrase 'working reproducer'?
data_param is 41 rows with this structure, to me, it's a 4 x 41 array, but I don't know Python terminology. 

[15000.0, 0.00002, 0.5, 0.5],

Cheers,
Frank

Python doesn’t use array terminology per se. Python uses lists. In the OPs case, he is using nested lists (a list of lists).

I tried to execute the code that you initially posted, it did not work!
If something like the below was provided, I would have been able to execute on my laptop and better understand your question:

import time

test_param = [15000.0, 0.00002, 0.5, 0.5],

for row in test_param:
    freq, time_scale, att, delay = row
    print(att)
    time.sleep(delay)

See also the documentation for what is an array in Python.