title: Python - TypeError: write() argument must be str, not bytes
body: <p>I've got an error message from python.
  It's a code that extracts phonetic symbols from the oxford online dictionary.</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "C:\Download\Oxford_PhoneticSymbol\Oxford_PhoneticSymbol.py", line 24,
    in 
        fw.write((result + "\n").encode("utf-8")) TypeError: write() argument must be str, not bytes</p>
  </blockquote>
  
  <p>Original source is from; <a href="https://my.oschina.net/sfshine/blog/3076588" rel="noreferrer">https://my.oschina.net/sfshine/blog/3076588</a></p>
  
  <pre><code># -*- coding: UTF-8 -*-
  import requests
  import time
  from bs4 import BeautifulSoup
  f = open('./words.txt')
  fw = open('./result.txt','a')
  
  line = f.readline()
  index = 0
  while line:
      index = index+1
      url = "https://www.oxfordlearnersdictionaries.com/definition/english/" + line.strip()
      print(str(index) + ":" + url)
      wbdata = requests.get(url,headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'}).text
      soup = BeautifulSoup(wbdata,'html.parser')
      news_titles = soup.select("span.pron-g &gt; span.phon")
      # print(news_titles)
      result = ''
      for n in news_titles:   
          title = n.get_text()    
          if 'NAmE' in title:
              result += '['+title.replace('NAmE','').replace('//','') + ']'
      print(result)  
      fw.write((result + "\n").encode("utf-8"))
      line = f.readline()
      time.sleep(0.1)
  
  fw.close()
  f.close()
  </code></pre>
  
  <p>Like it needed, I have put two txt files in the same directory.
  And I filled a few words in words.txt and made the result.txt as blank, but I got the error.</p>
  
  <pre><code>(words.txt, saved as UTF-8)
  source
  technic
  resource
  power
  box
  created
  computer
  charged
  learned
  </code></pre>
  
  <p><strong>Any Idea how to fix this?</strong></p>