2016-12-02 163 views
-1

我試圖在文件中寫:寫入文件Python,錯誤?

f = open('parsed.txt', 'w') 

f.write(url + '\n' + title + '\n' + email + '\n\n') 

,但我得到的錯誤:

Traceback (most recent call last): 
    File "C:/Users/Brand Cream/AppData/Local/Programs/Python/Python35/index.py", line 122, in parsePage 
    f = open('parsed.txt', 'w') 
TypeError: open() takes 1 positional argument but 2 were given 

有什麼不對?

+6

你碰巧在你的代碼中擁有自己的'open'函數嗎? –

+2

你有自己的函數'open()'或者你使用'from ... import *',它會覆蓋oryginal'open()'函數。 – furas

回答

5

您可能在代碼的其他位置有一個叫做open的函數,它只接受一個參數。這就是你得到這個錯誤的原因。

+0

是的,你是對的,但我得到空文件,所以,我創建文件在我運行腳本的同一目錄 – MisterPi