-1
import codecs
with open(filename+'.txt', 'a+', encoding='utf-8') as f:
    for tweet in list_of_tweets:
        print(tweet.text.replace('\r','').replace('\n','')+'|')
        f.write(tweet.text.replace('\r','').replace('\n','')+'|')

Its showing

TypeError Traceback (most recent call last) in () 1 import codecs ----> 2 with open(filename+'.txt', 'a+', encoding='utf-8') as f: 3 for tweet in list_of_tweets: 4 print(tweet.text.replace('\r','').replace('\n','')+'|') 5 f.write(tweet.text.replace('\r','').replace('\n','')+'|')

TypeError: 'encoding' is an invalid keyword argument for this function

Rakesh
  • 81,458
  • 17
  • 76
  • 113
Arindam Taak
  • 53
  • 1
  • 1
  • 5

1 Answers1

5

If you are using python 2 then try:

import codecs
from io import open
with open(filename+'.txt', 'a+', encoding='utf-8') as f:
    for tweet in list_of_tweets:
        print(tweet.text.replace('\r','').replace('\n','')+'|')
        f.write(tweet.text.replace('\r','').replace('\n','')+'|')

The usual open for python2 does not accept encoding.

hygull
  • 8,464
  • 2
  • 43
  • 52