import urllib
def read_text():
quotes = open(r"C:\moviequotes\moviequotes.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(r"http://www.wdyl.com/profanity?q="+text_to_check")
output = connection.read()
print(output)
connection.close()
read_text()
我收到此错误:EOL扫描字符串文字时。我究竟做错了什么? 这是文件:
-- Houston, we have a problem. (Apollo 13)
-- Mama always said, life is like a box of chocolates. You never know what you are going to get. (Forrest Gump)
-- You cant handle the truth. (A Few Good Men)
-- I believe everything and I believe nothing. (A Shot in the Dark)
答案 0 :(得分:1)
交换:
connection = urllib.urlopen(r"http://www.wdyl.com/profanity?q="+text_to_check")
带
connection = urllib.urlopen(r"http://www.wdyl.com/profanity?q="+text_to_check)
你有一个额外的双引号。