2016-12-28 61 views
0

下面是我的python代碼來檢查文件中的罵人詞。 但我無法找到爲什麼編譯器顯示錯誤:module 'urllib' has no attribute 'urlopen'我的代碼urlopen函數有什麼問題?

import urllib 
def read_txt(): 
    quote = open("c:\\read.txt") #for opening the file 

    content = quote.read() #for reading content in a file 
    print(content) 
    quote.close() #for closing the file 
    check_profanity(content) 


def check_profanity(text): 
    connection = urllib.urlopen("https://www.wdylike.appspot.com/?q=" + text) 
    ouput = connection.read() 
    print(output) 
    connection.close() 
read_txt() 
+1

? –

回答

1

嗯,因爲urllib沒有urlopen方法。

在Python2你應該使用urllib2,而在Python 3,你應該,你使用的是哪個版本的Python使用urllib.request