if the input file has any non digit values, unable to print ValueError for ex: if the input file has values:
100
200
300
The values should be appended to the list
if values are:
100
s
200
it should pop out error
provided in code
m = 0
j = []
with open("file_name.txt", mode="r") as f:
file_lines = f.readlines()
while m < len(file_lines):
values = file_lines[m].strip()
try:
if values.isdigit():
j.append(values)
except ValueError:
print("Input values given in file_name.txt are not integers '%s'" % values.strip())
pass
m = m + 1
f.close()
print(j)
output should be print("Input values given in file_name.txt are not integers '%s'" % values.strip()) if input values have any non digit value