title: Python help reading csv file failing due to line-endings
body: <p>I'm trying to create this script that will check the computer host name then search a master list for the value to return a corresponding value in the csv file. Then open another file and do a find an replace. I know this should be easy but haven't done so much in python before. Here is what I have so far...</p>
  
  <pre><code>masterlist.txt  (tab delimited)
  Name                 UID
  Bob-Smith.local      bobs
  Carmen-Jackson.local carmenj
  David-Kathman.local  davidk
  Jenn-Roberts.local   jennr
  </code></pre>
  
  <p>Here is the script that I have created thus far</p>
  
  <pre><code>#GET CLIENT HOST NAME
  import socket
  host = socket.gethostname()
  print host
  
  #IMPORT MASTER DATA
  import csv, sys
  filename = "masterlist.txt"
  reader = csv.reader(open(filename, "rU"))
  
  #PRINT MASTER DATA
  for row in reader:
    print row
  
  #SEARCH ON HOSTNAME AND RETURN UID
  
  
  
  #REPLACE VALUE IN FILE WITH UID
  #import fileinput
  #for line in fileinput.FileInput("filetoreplace",inplace=1):
  #   line = line.replace("replacethistext","UID")
  #   print line
  </code></pre>
  
  <p>Right now, it's just set to print the master list. I'm not sure if the list needs to be parsed and placed into a dictionary or what. I really need to figure out how to search the first field for the hostname and then return the field in the second column. </p>
  
  <p>Thanks in advance for your help,
  Aaron</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>: I removed line 194 and last line from masterlist.txt and then re-ran the script. The results were the following:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):<br>
    File "update.py", line 3, in 
        for row in csv.DictReader(open(fname),
    delimiter='\t'):   File
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/csv.py",
    line 103, in next
        self.fieldnames   File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/csv.py",
    line 90, in fieldnames
        self._fieldnames = self.reader.next()
    _csv.Error: new-line character seen in unquoted field - do you need to open
    the file in universal-newline mode?</p>
  </blockquote>
  
  <p>The current script being used is...</p>
  
  <pre><code>import csv
  fname = "masterlist.txt"
  for row in csv.DictReader(open(fname), delimiter='\t'):
    print(row)
  </code></pre>