思路:

读取文本 -> 检查文本 -> 判断输出

Python 内置函数文档
urllib 的文档

import urllib
def read_text():
    quotes = open("/Users/gloriazhang/Documents/movie_quotes.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="+text_to_check)
    output = connection.read()
    #print(output)
    if "true" in output:
        print("Profanity!")
    elif "false" in output:
        print("This ducument has no curse words!")
    else:
        print("Could not scan")
    connection.close()
    
read_text()

输出如下:002 检索英文文档中的冒犯语(Python)

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2022-01-01
  • 2022-02-28
  • 2022-12-23
  • 2022-02-16
  • 2021-08-27
猜你喜欢
  • 2021-08-10
  • 2021-12-19
  • 2021-11-21
  • 2022-01-10
  • 2021-12-11
  • 2021-10-23
相关资源
相似解决方案