how to count the number of lines in one text file and create a function of that?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mari2025
    New Member
    • Apr 2013
    • 6

    how to count the number of lines in one text file and create a function of that?

    Dear friends,
    I would like to make a function in which I can count the number of lines in some text files and finally sum up these numbers. I would be thankful if somebody guide me how to do it in python?
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    1. Initialize an empty list
    2. Iterate over the list of file names
    3. For each file, open it
    4. Count the number of lines using len(readlines)
    5. Append the value to the list
    6. Close it
    7. Use sum(list)

    Done!

    Comment

    Working...