Thank you for all your helps on Friday. Sorry for maybe my simple questions. as I am a beginner in Python, at times I wld face some questions which are easy for more expert people but I try to improve myself.
I am going to clarify my previous question more detail. I have some text files, with your guidance ,I am able to count the lines of these text files. i would like to create a new text file as an output that in each line of this new file I have the name of the input file with the number of the lines with space and the last line of this file contain the sum of the line numbers. For instance I have some files as : points1.txt, points2.txt and points3.txt. The output file wld be :
point1 144798 point2 100000 point3 258627 sum 503425
The code I have is:
import os folder = 'E:/MLS_HFT/TEST/Stuttgart_2009_pointclouds/'
def total_lines():
count_line = 0
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
infile= open(infilename, 'r')
for lines in infile:
i+=1
outfile = ["%s " %i]
return i
outfile = ["%s " %i]
outfile.write("\n".join(output))
outfile.close()
return outfile
total_lines (infile,i)
count_line = count_line + i
output = ["%s %s" %(item.strip() ,count_line) for item in outfile]
outfile.write("\n".join(output))
I wld be thankful to have your guidance.