2017-02-04 25 views
-1
with open('recent_tweets_bmw.csv', 'wb', '\r\n') as csvfile: 1 
    wf = csv.writer(csvfile, delimiter=',', quotechar='"') 

for tweet in tweets: 
    wf.writerow(['bmw', tweet['text'].encode("utf-8")])[enter image description here][1] 

Traceback (most recent call last) in() 4 # to handle text encoding challenges 5 ----> 6 with open('recent_tweets_bmw.csv', 'wb', '\r\n') as csvfile: 7 8我怎麼仍然得到一個錯誤代碼,我已經複製這個複製單詞並仍然有問題...任何人都得到這個之前?

TypeError: an integer is required

回答

3

你傳入'\r\n'open()作爲第三位置說法。但那是buffer參數的位置(緩衝區的大小)。我想你想使用命名參數語法和說newline='\r\n'或一些這樣的...

+0

我試圖進入代碼的方式,但只是發現它是無效的關鍵字? ---------------------------------------------- ----------------------------- TypeError Traceback(最近呼叫的最後一個) in () 1 import csv ----> 3 open('name-brands.csv','w',newline ='r \ n')as csvfile: 4 wf = csv.writer(csvfile ,delimiter =',', 5 quotechar ='「') TypeError:'newline'是此函數的無效關鍵字參數 –

+0

您似乎在使用python2,儘管將問題標記爲python-3.x。你應該將開放模式設置爲'Uw'或'Uwb'? –

+0

謝謝!得到它了。 –

相關問題