Can someone please help me why the below readline code is not giving expected result ?
f=open('Python_practice/Sample1.txt','r')
while f.readline() != '':
print(f.readline(),end = '')
f.close()
Here - Am getting below o/p ( first and 3rd line is not coming ):
How are you ?
What about you ?
While when I am running below code, I am getting expected o/p.
f=open('Python_practice/Sample1.txt','r')
while True:
data = f.readline()
if data == '':
break
else:
print(data,end = '')
f.close()
Hello!
How are you ?
I am fine, thanks.
What about you ?
f=open('Python_practice/Sample1.txt','r')
while f.readline() != '':
print(f.readline(),end = '')
f.close()
I am expecting :
Hello!
How are you ?
I am fine, thanks.
What about you ?
Am getting below o/p ( first and 3rd line is not coming ):
How are you ?
What about you ?