title: Check for number of columns in each row of CSV
body: <p>I have the following Python code:</p>
  
  <pre><code>import os
  import csv
  import sys
  
  g = open('Consolidated.csv', "wb")
  for root, dirs, files in os.walk('D:\\XXX\\YYY\\S1'):
      for filename in files:
              pathname = os.path.join(root, filename)
              symbol = filename.rpartition('_')[-1].rpartition('.')[0]
              reader = csv.reader(open(pathname, 'rU'))
              writer = csv.writer(g, delimiter='\t', quotechar='"', quoting=csv.QUOTE_ALL)
  
              for row in reader:
                  row.insert(0, symbol.upper())
                  if len(row[2]) == 3:
                      row[2] = '0'+row[2]
                  writer.writerow(row)
  </code></pre>
  
  <p>The basic idea is that I have a couple of CSV files in S1 that I need to merge to a large CSV. The files are named in a funny way, which leads to the rpartition and row manipulations in the code. </p>
  
  <p>This code works fine, but my question is as follows: how does one check the number of columns in EACH row of the CSV file? An example: if an input CSV file is in the following format, expected to have five columns: 1,2,3,4,5, the code would display "1" "2" "3" "4" "5" (seperated by tabs) in the consolidated file. Now let's say for whatever reason one row entry in the CSV file is like: 6,7,8. So it stops abruptly without all the columns filled in. In this case, I want the code to ignore this line and not produce "6" "7" "8" into the consolidation. </p>
  
  <p>Could someone kindly provide code on how to do so? For each row in the input CSVs I want to check if it is a full row before manipulating it.</p>
  
  <p>Any help would be massively appreciated.</p>
  
  <p>Warm Regards.</p>