python - NameError:名称'urllib'未定义
问题描述
大家好,现在我知道堆栈溢出有解决方案我只是不明白,这是我的代码
enter code here
import urllib.request import urlopen
def read_text():
quotes = open(r"C:\Users\LEON\Desktop\python\Swear_words.txt")
contents_of_file = quotes.read()
print(contents_of_file)
quotes.close()
check_profanity(contents_of_file)
def check_profanity(text_to_check):
connection =
urllib.urlopen("http://www.wdylike.appspot.com/q=s"+text_to_check)
output = connection.read()
read_text()
错误 NameError: 名称 'urllib' 未定义
解决方案
import 语句本身的语法不正确。它应该/可能是
from urllib.request import urlopen
那么最后第三行不需要urllib
前缀
urlopen("http://www.wdylike.appspot.com/q=s"+text_to_check)
推荐阅读
- r - 如何在R(ccf)的互相关列表中找到最大滞后?
- jenkins - 使用从组织的 SSO 获得的 authtoken 请求 jenkins rest api
- python - 如何在 Python 中根据年龄计算文件?
- java - 使用 GSON 库获取 JSON 对象/数组而不转换为 pojos
- amazon-web-services - 如何在 terrafom 的 cognito 中启用 PreventUserExistenceErrors
- github - 中心文字MARKDOWN显示 GITHUB
- php - Symfony 5 Api 测试 createClient() LogicalException
- file - 从文件中读取字节并使用 `pom` 解析器库解析它们
- javascript - 拆分字符串以构建对象
- python - KNeighborsClassifier 中是否有加权指标?