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?
User Profile
Collapse
Profile Sidebar
Collapse
mari2025
Last Activity: May 24 '13, 12:32 PM
Joined: Apr 2 '13
Location:
-
mari2025 started a topic how to count the number of lines in one text file and create a function of that?in Pythonhow to count the number of lines in one text file and create a function of that?
-
thank you very much for your helpful guidance. I would like to ask another question. I am going to apply the above code for many files those are in one folder. in your view, what is the fastest approach, I was thinking I should create a function or is there any other methods for to do it as quick as possible? -
I have changed your code a bit and now it shows what I really want:
but still I am not sure that no where I have introduced the new column type...Code:data = open("E:/SAGA/data/325125404.all","r").readlines() output = ["%s\t%s" %(item.strip(),1) for item in data] f = open("E:/SAGA/data/325125404_mod.all","w") f.write("\n".join(output)) f.close()Leave a comment:
-
I also have question about "%s,", does not it use for the strings? as the 1 and 2 are numbers, should I use integer?Leave a comment:
-
thank you very much for your prompt reply.
I tried it and works. Moreover,
if I want to add the new column using space between the new and the others what should I do?Leave a comment:
-
add new field(column) to a file
Hello,
I am beginner in Python and I need your guidance about the task I am given. I have to read a laser data file in python and then add two new columns to the data and fill them with specific integer values. I was able to read the file but was not successful in adding the new columns.I would be happy if you can kindly help me with it.
...Code:f = file("E:/SAGA/data/325125404.all", "r") >>> f.read()Last edited by bvdet; Apr 2 '13, 02:35 PM. Reason: Please use code tags when posting code [code]....[/code]
No activity results to display
Show More
Leave a comment: