title: count lines in multiple files and output along with file names
body: <p>I wanted to get the number of lines in each file in a folder and print out the number of lines along with the file name adjacently. Having just entered the world of programming, I managed to write this short code, borrowing them from here and there.</p>
  
  <pre><code>#count the number of lines in all files and output both count number and file name
  import glob
  list_of_files = glob.glob('./*.linear')
  for file_name in list_of_files:
      with open (file_name) as f, open ('countfile' , 'w') as out :
          count = sum (1 for line in f)
          print &gt;&gt; out, count, f.name
  </code></pre>
  
  <p>But this gives an output of only one of the file. </p>
  
  <p>This could be done pretty easily using <code>wc -l *</code>.linear  in shell, but I wanted to know how to do this in python.</p>
  
  <p>P.S : I sincerely hope I am not duplicating questions!</p>