473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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?
Apr 19 '13 #1
1 1531
bvdet
2,851 Expert Mod 2GB
  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!
Apr 19 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stephen LeBlanc | last post by:
I'm having an issue coding in VB.NET. I'm trying to create a program that let's a user choose 2 files, using the OpenFileDialog control:1 file exists and contains data for extraction, the other...
1
by: tarunsarkar | last post by:
Please help me out Is there any function in Borland C++ Builder which will return the total no of line of a text file
5
by: JHNielson | last post by:
I have a somewhat simple question, but have been baffled by it for a while, and now I'm on a tight deadline - have to get it done within 24 hours. I am trying to export a set of files to my hard...
1
by: gobblegob | last post by:
Hello, I am trying to use a text file as input but it could be in two locations. for example : Open "c:\mytext.txt" For Input As #1 While Not EOF(1) Line Input #1, temp$ ...
5
by: gobblegob | last post by:
Hello, I am trying to use a text file as input but it could be in two locations. for example : Open "c:\mytext.txt" For Input As #1 While Not EOF(1) Line Input #1, temp$ alltext$ = alltext$ &...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
5
by: Johnymap | last post by:
Hi everyone I have text file which looks like these: "index.txt" Johan 22 sebaya "home.hml" Mpho 23 leboa "index.frt" Tedesca 24 teba My problem is i want to read the number on the last...
7
by: kashif73 | last post by:
I have a text file , from which I read a single line & display it in my form. How can I read the line number for that particular line, which is being displayed in my form?? Thanks.
3
by: hkeiner | last post by:
I have an Access 2003 MDB database that uses the "currentuser()" function extensively (in queries and macros) to control what a particular user can see and do. In Access 2007 (which no longer uses...
4
by: lightning18 | last post by:
I have a list of incorrect words called # words and another list containing my txt file # text. I want to print the line number of the words located in the text. I get the following error for my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.