-1
import nltk
from urllib import request

url = "http://www.site.uottawa.ca/~diana/csi5386/A1_2020/microblog2011.txt"
response = request.urlopen(url)
raw = response.read().decode('utf8')
tokens = nltk.word_tokenize(raw)
tokens

In the above code the output is in 'tokens' in the form of list. How to copy this list into a text file?

john
  • 21
  • 2
  • Does this answer your question? [Directing print output to a .txt file in Python 3](https://stackoverflow.com/questions/36571560/directing-print-output-to-a-txt-file-in-python-3) – M_S_N Jan 23 '20 at 04:37
  • Does this answer your question? [Python 2.7: Print to File](https://stackoverflow.com/questions/9316023/python-2-7-print-to-file) – Victor Pudeyev Jan 31 '20 at 03:21

1 Answers1

1

You would need to do something like this:

with open('filename.txt', 'w') as f:
    for i in tokens:
        f.write(i)  
Gary
  • 909
  • 8
  • 20