I've written this code with the aim of exiting the code once the last line is reached and I've tried using the commented code but it only prints every alternating line.
try:
a = sys.argv[1]
with open(a, 'r') as f:
print(f.readline().strip('\n'))
while True:
x = input()
if x == '':
print(f.readline().strip('\n'))
# if not f.readline():
# exit()
continue
if x == 'q':
exit()
except OSError:
print("Error: Cannot open specified file.")
exit()
except IndexError:
print('Usage: python3 less.py <filename>')
exit()