I have the following code which is used to extract a substring from each line of text on a file and put in a list of strings.
distribution = []
with open("./Output_Files/datafile.txt", "r") as fileRead:
for line in fileRead:
distr_chop = line.split()[3:]
distribution.append(distr_chop)
Then I convert each string in the list to an integer:
distribution = [int(i) for i in distribution]
However, I get an error when printing the list.
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
- What is wrong with my code?
- What other way could I extract the substring directly to an integer?
distr_chopis a list[3:]is a slice. It makes a list.distribution.extend(distr_chop)