+ 2
How to count total lines in a file..using file handling concept in python and is there any EOF in python like C?
I tried many times..but i was unsuccessful. How to count a line,i tried count('\n') by reading file but it doesn't work for me.
11 Respuestas
+ 3
So use this:
len(text.split('\n'))
That was what I was trying to say.
+ 1
Ya hope this works for me,thanks man.
+ 1
Excuse me. My hand got over delete section. I didn't want to do that.
If you forgot my answer I can type it again.
+ 1
Now i understand it
+ 1
First split the text of file.
And then count newline character and adding 1 gives total lines 😁
+ 1
No no. If you want to count newlines you shouldn't split text.
Just count them:
text.count('\n')+1
+ 1
No bro...i tried this in my first attempt but it doesn't count \n in file
+ 1
It gives value 1 means text.count('\n') ==0
+ 1
Hope this works.
+ 1
Me, too.
I can't believe that trick doesn't work.
I think you better check it on different files to see what's the problem
+ 1
Ya i try it tommorow,now it's time to go to bad for sleep.😴😪