2016-12-28 62 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