Python line count in a text file

Pubblicato il: 27 giugno 2021
sul canale di: CS School
532
8

Python program that shows how to open a text file and access file contents line by line and print the total line count in the text file.

***********IMPORTANT NOTICE********************

As we can see that there is an extra line gap between every two lines. It occurs because the Loop also printed '\n' newline character (existed at the end of each line) as a new line. So to fix this issue we can use the rstrip() method in the following way:

for line in handle:
line = line.rstrip()
print(line)

Hence it'll strip the newline character away from the right!
#python #programming


In questa pagina del sito puoi guardare il video online Python line count in a text file della durata di ore minuti seconda in buona qualità , che l'utente ha caricato CS School 27 giugno 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 532 volte e gli è piaciuto 8 spettatori. Buona visione!