title: TypeError: argument 1 must have a "write" method -- creating csv from dict
body: <p>I'm trying to create a csv from a dict, but I'm receiving the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>in create_csv
      writer = csv.writer('userInfo.csv')
  TypeError: argument 1 must have a "write" method
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#Create dict file to test
  userInfoDict = {'orgID': '17', 'firstName': 'TestFirstName', 'lastName': 'TesLastName',
                  'emailAddress': 'test@test.com', 'phoneNumber': '123-456-7890',
                  'isoCountryCode': 'US'}
  
  def create_csv(userInfoDict):
      import csv
  
      userInfo = open('userInfo.csv', 'wb')
  
      for key in userInfoDict:
          if len(userInfoDict['orgID']) == 0:
              print('Not a valid user: No orgID')
              return None
          elif len(userInfoDict['firstName']) == 0:
              print('Not a valid user: No First Name')
              return None
          elif len(userInfoDict['emailAddress']) == 0 or len(userInfoDict['phoneNumber']) == 0:
              print('Not a valid user: No Email or Phone')
              return None
          else:
              writer = csv.writer(userInfo, delimiter=',')
              for key, value in userInfoDict.items():
                  writer.writerow([key], [value])
          return
  
  create_csv(userInfoDict)
  </code></pre>