sum(1 for _ in f) how to count the total number of lines in a text file using python

https://stackoverflow.com/questions/19001402/how-to-count-the-total-number-of-lines-in-a-text-file-using-python

with open('data.txt') as f: print sum(1 for _ in f)

posted on 2021-08-19 16:27  cdekelon  阅读(88)  评论(0)    收藏  举报

导航