下面是我的python代码来检查文件中的诅咒词。
但是我无法找到编译器显示错误的原因:module 'urllib' has no attribute '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()
因为
urllib
没有urlopen
方法。你知道吗在Python2中应该使用
urllib2
,而在python3中应该使用urllib.request
在python3中,^{} 现在是一个收集多个模块的包。^{} is now a part of ^{} module :
然后使用它:
相关问题 更多 >
编程相关推荐