I'm quite lost with this one, im currently making a program that gets an input from a .txt document, the first line says: "From:0 To:4", and my goal is to get the "0" and "4" values.
This is what im currently doing:
with open('graph.txt') as matrix: linea = matrix.readlines() for line in linea: if line.startswith('From:'): start = line.rsplit(':')[-1].strip() start= int(start,10) elif line.__contains__('To:'): end = line.split(':')[-1].strip() end = int(end,10)
I made it this way because before the "from:" and "to:" were in two different lines, but I needed to set them in the same one. The prolem righ now is that whenever i run the code I got "NameError: name 'end' is not defined".