I’m working with a script that fits a line to a data set and outputs some fit parameters. The command that runs the fitter looks like:
fitter = Fitter(hdf2.root.OM01, plot=False).
I’d like to loop this command so that it outputs the fit parameters for the files 'hdf2.01', 'hdf2.02', ... 'hdf2.50'
How can I loop this code?
If I understand correctly, you have an object that has numbered properties (
OM01throughOM50). You can generate these attribute names with a loop, and use getattr to retrieve them from the object.If your object is called
root, as it is in your comment, you could do the following:or, if you like list comprehensions (and who doesn’t):
I guess you need to use these parameters with
Fitter, which you could do as follows:EDIT: If your files just have the names “hdf2.root.OM01”, “hdf2.root.OM02”, etc. you can just do this: