how do you initialize a runtime array with a name from the list?

I strongly discouraged you to use locals() (or globals() or vars()) to manipulate the variables dynamically:

list_1 = ['File_A', 'File_B', 'File_C', 'File_D']
for v in list_1:
    locals()[v] = np.array(0)

Output:

>>> File_A
array(0)

>>> File_B
array(0)

>>> File_C
array(0)

>>> File_D
array(0)

Note: File_A, File_B, … should be valid Python name identifiers.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top