You can download this code by clicking the button below.
This code is now available for download.
This function counts the number of lines in a specified file by reading the file content and returning the line count.
Technology Stack : os, sys, time, json, re
Code Type : Function
Code Difficulty : Beginner
import os
import sys
import time
import json
import re
def file_lines_count(file_path):
"""
计算指定文件的行数。
"""
with open(file_path, 'r') as file:
lines = file.readlines()
return len(lines)