1

I would like to assign some value in incremental parameter name by for loop but there are some error to recognize the parameter name as below.

for i in range(1,4):
    print i
    Name_i = h5py.File(filename_BS_i, "r")

What I expect,

1st for loop Name_1 = h5py.File(filename_1, "r")

2nd for loop Name_2 = h5py.File(filename_2, "r") . .

Do you have any idea.?

I know, it works if I change parameter i_Name instead of Name_i

Thanks!

1
  • Format String Commented Jun 26, 2017 at 7:08

1 Answer 1

0

Consider using a dictionary. e.g.

Names = {} for i in range(1,4): Names[i] = h5py.File(filename_BS_ + str(i), "r")

Sign up to request clarification or add additional context in comments.

2 Comments

This will store all your files in a dictionary, which can be indexed by the corresponding integer.
Thanks! it's working!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.