菜鸟Python(4)

不敬语查询

1
2
3
4
5
6
7
8
9
# 定义一个读取的方法
def read_text():
# 调用 open 内置函数打开文件
quotes = open("E:\ButterKnife.txt")
# 读取文件
contents_of_file=quotes.read()
print(contents_of_file)
quotes.close()
read_text()

内置函数

Ptyhon 中的内置函数

利用代码访问网站

不敬语查询网站 可能需要进行科学上网,
利用这个网站后缀,进行查询是否存在不文明的字

1
2
3
4
5
6
7
8
9
10
11
12
13
import urllib
def read_text():
quotes = open("E:\ButterKnife.txt")
contents_of_file=quotes.read()
print(contents_of_file)
quotes.close()
check_profanity(contents_of_file)
def check_profanity(check_text):
connection=urllib.urlopen("http://www.wdylike.appspot.com/?q="+check_text)
output=connection.read()
print(output)
connection.close()
read_text()

(*^▽^*)