python how to count the lines in a file
# Basic syntax:
count = len(open('/path/to/the/file.ext').readlines())
python how to count the lines in a file
# Basic syntax:
count = len(open('/path/to/the/file.ext').readlines())
python 3 text file leng
f = open("filename", "r") #Load file in any mode that's able to read, ie r, r+, w+ etc
#to get length
len(f.readlines())
#To iterate over each line
for line in f.readlines(): #file.readlines(), splits the file into a list, where each element is a seperate line
print(line)
how to know how much lines a file has using python
filename = "test.txt"
count = 0
with open(filename, 'r') as f:
for line in f:
count += 1
print("Total number of lines is:", count)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us