title: Python Function Define of HTML Table Code
body: <p>I am trying to create define a function that will create HTML tables from input CSV files. The code works by itself but I cannot get it to work correctly as a function. It is: </p>
  
  <pre><code>def write(in_name):
      table = ''
      with open(in_name, encoding="utf-8-sig") as csvFile:
          reader = csv.DictReader(csvFile, delimiter=',')
          table = '&lt;tr&gt;{}&lt;/tr&gt;'.format(''.join(['&lt;td&gt;{}&lt;/td&gt;'.format(header) for header in reader.fieldnames]))
          for row in reader:
              table_row = '&lt;tr&gt;'
              for fn in reader.fieldnames:
                  table_row += '&lt;td&gt;{}&lt;/td&gt;'.format(row[fn])
              table_row += '&lt;/tr&gt;'
              table += table_row
      table = table.replace(u'\xa0', u' ')
  
  write("2016motogp.csv")
  
  table
  </code></pre>
  
  <p>Which just gives the output ' '.</p>
  
  <p>Ideally I would like to choose the output name so I could save multiple tables to be input in various areas.</p>
  
  <p>If anyone could help me it would be greatly appreciated.
  Thanks in advance,</p>