title: Replace Special Characters in Field Names in Python
body: <p>I am trying to replace the special characters in the field name (or first row) in my CSV file using python.  There are a lot of questions closely related to special characters but I can't seem to find anything for the first row.  The script I have replaces them in the whole document but I only want it to do it in the first row.  I thought if I used readline instead of readlines, it would work but that just makes most of the file disappear.  Any help would be appreciated.  My code is below.</p>
  
  <pre><code>import os, sys, csv
  
  lines = []
  
  with open('C:/Characters.csv', 'r') as input:
      lines = input.readlines()
  
  conversion = '-"/.$'
  newtext = '_'
  outputLines = []
  for line in lines:
      temp = line[:]
      for c in conversion:
          temp = temp.replace(c, newtext)
      outputLines.append(temp)
  
  with open('C:/Characters_out.csv', 'w') as output:
      for line in outputLines:
          output.write(line + "\n")lines = []
  </code></pre>