I have multiple files with similar names like datacard_20_higgs.txt, datacard_30_higgs.txt. I need to run the same command on all of these files. The problem is, that I do not understand how to import all of these files at ones. If I have that the for loop for the command should not be too hart but I cannot import them somehow
ROOT Version: Not Provided Platform: Not Provided Compiler: Not Provided
Itâs not working because I get the following error:
NameError: global name âFormâ is not defined
So what I want is to get the changeing part of those file names so I can use that to create other files with them corresponding to the ones I took it from
Sorry, itâs not super clear what you mean with âaccess whatâs inside *â, maybe it would be helpful if you posted the code you have (the relevant lines, that is). Also the issue doesnât seem related to ROOT?
If I understand correctly, for a list of strings of the form "datacard_N_higgs.txt", where N is an integer, you want to extract the value of N. If files is the python list with these strings, one way to do it is:
prefix = "datacard_"
suffix = "_higgs.txt"
for file in files:
N = int(file[len(prefix):-len(suffix)])
Awesome, that worked, thank you so much!
Also is there maybe a way to sort them from lower value to higher? Right now python is making a random order:
210
270
300
290
230
260
220
160
250
180
170
280
190
240
200