0

I have not gotten good answers to this question, both by searching and through waiting for replies and I think it was because my first iteration of the question was poorly worded.

ALL I WANT to do is add two columns to a file that looks like this:

name    phone   email   website
Diane Grant Albrecht M.S.           
Lannister G. Cersei M.A.T., CEP 111-222-3333    cersei@got.com  www.got.com
Argle D. Bargle Ed.M.           
Sam D. Man Ed.M.    000-000-1111    dman123@gmail.com   www.daManWithThePlan.com
Sam D. Man Ed.M.            
Sam D. Man Ed.M.    111-222-333     dman123@gmail.com   www.daManWithThePlan.com
D G Bamf M.S.           
Amy Tramy Lamy Ph.D.            

So that it looks like this:

name    phone   email   website    area   degrees
D G Albright                                                                      M.A.          
Lannister G. Cersei 111-222-3333    cersei@got.com  www.got.com    CEP    M.A.T.
Argle D. Bargle                                                             Ed.M.           
Sam D. Man  000-000-1111    dman123@gmail.com   www.daManWithThePlan.com   Ed.M.
Sam D. Man                                                                        Ed.M.         
Sam D. Man  111-222-333     dman123@gmail.com   www.daManWithThePlan.com      Ed.M.
D G Bamf                                                                          M.S.          
Amy Tramy Lamy 

Despite the fact that 'writeheader()' is mentioned on several posts, when I past it a list of fieldnames, it returns an error.

TypeError: writeheader() takes exactly 1 argument (2 given)
logout

Here's what I have so far:

with open('ieca_first_col_fake_text.txt','r') as input:
    with open('new_col_dict.txt','w') as output:
        dict_writer = csv.DictWriter(output, fieldnames, delimiter = '\t')
        dict_reader = csv.DictReader(input, delimiter = '\t')
        #dict_writer.writeheader(fieldnames)
        for row in dict_reader:
            print row

This doesn't yield a txt file that has headers...

goldisfine
  • 4,742
  • 11
  • 59
  • 83

1 Answers1

0

from http://docs.python.org/2/library/csv.html#csv.DictWriter.writeheader it's clear how to use it - without any additional argumets, i.e.:

 dict_writer.writeheader()
Aprillion
  • 21,510
  • 5
  • 55
  • 89