Convert the integer to a string THEN iterate over the lines in the file, checking if the current line matches the elementid
.
elementid = 123456 # given
searchTerm = str(elementid)
with open('wawi.txt', 'r') as f:
for index, line in enumerate(f, start=1):
if searchTerm in line:
print('elementid exists on line #{}'.format(index))
Output
elementid exists on line #3
Another approach
A more robust solution is to extract all numbers out of each line and find the number in said numbers. This will declare a match if the number exists anywhere in the current line.
Method
numbers = re.findall(r'\d+', line) # extract all numbers
numbers = [int(x) for x in numbers] # map the numbers to int
found = elementid in numbers # check if exists
Example
import re
elementid = 123456 # given
with open('wawi.txt', 'r') as f:
for index, line in enumerate(f, start=1):
if elementid in [int(x) for x in re.findall(r'\d+', line)]:
print('elementid exists on line #{}'.format(index))