title: What is the difference between .DictWriter() vs .write() in Python?
body: <p>As I was learning about opening files in Python I came across both .write and .DictWriter. The Files section was split into 3 sections: Regular files, CSV files, and JSON files.</p>
  
  <p>My question is: Can we use .write() in a CSV file and .DictWriter() in a regular txt file?</p>
  
  <p>From my notes I have:</p>
  
  <pre><code>#Writing a New File
  
  with open('generated_file.txt', 'w') as gen_file:
    gen_file.write("What an incredible file!")
  </code></pre>
  
  <p>using .write() for a regular txt file</p>
  
  <p>and:</p>
  
  <pre><code>#Writing a CSV File
  
  big_list = [{'name': 'Fredrick Stein', 'userid': 6712359021, 'is_admin': False}, {'name': 'Wiltmore Denis', 'userid': 2525942, 'is_admin': False}, {'name': 'Greely Plonk', 'userid': 15890235, 'is_admin': False}, {'name': 'Dendris Stulo', 'userid': 572189563, 'is_admin': True}] 
  #In our code above we had a set of dictionaries with the same keys for each, a prime candidate for a CSV.
  
  import csv
  #We import the csv library,
  
  with open('output.csv', 'w') as output_csv:
  #and then open a new CSV file in write-mode by passing the 'w' argument to the open() function.
  
    fields = ['name', 'userid', 'is_admin']
  #We then define the fields we’re going to be using into a variable called fields.
  
    output_writer = csv.DictWriter(output_csv, fieldnames=fields)
  #We then instantiate our CSV writer object and pass two arguments. 
  #The first is output_csv, the file handler object. 
  #The second is our list of fields fields which we pass to the keyword parameter fieldnames.
  
    output_writer.writeheader()
  #Now that we’ve instantiated our CSV file writer, we can start adding lines to the file itself! 
  #First we want the headers, so we call .writeheader() on the writer object. 
  #This writes all the fields passed to fieldnames as the first row in our file.
  
    for item in big_list:
  #Then we iterate through our big_list of data. 
  #Each item in big_list is a dictionary with each field in fields as the keys.
  
      output_writer.writerow(item)
  #We call output_writer.writerow() with the item dictionaries which writes each line to the CSV file.
  </code></pre>
  
  <p>using .DictWriter() for a CSV file</p>
  
  <p>Can we use these write methods interchangeably in txt, and csv files?</p>