This is what I have:
When I try to do this, it shows me an error: IndexError: list index out of range
Could someone help?

with open(os.path.join(path, file.replace(".root", ".txt")), 'r') as f:
    lines = f.readlines()
htemp = TH1D(name, name, nBins, eMin, eMax)
for i in range(len(lines)):
    htemp.SetBinContent(i + 1, float(lines[i]))
entries = int(lines[-1])
return prepareHisto(htemp, xLabel, yLabel), entries

Normally, the exception traceback that python prints on the screen tells you the line number and statement where the error occurred. Can you post the whole traceback ?

I don't know if this would help you to understand!

Traceback (most recent call last):
  File "Desktop/python/check2.py", line 135, in readTextIntoHistogram
    entries = int(lines[-1])
IndexError: list index out of range

If there is no lines[-1] it means that the lines list is empty (there is no last item). Try to check the length of the list first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.