python - When I tried to pass data to a function from another it shows me a lot of errors -
this code worked successfully..
import urllib.request def profanity(): connection = urllib.request.urlopen('http://www.wdylike.appspot.com/?q='+'bal') output = connection.read() print(output) connection.close() profanity()
but want run code below caused problem me. want pass data being read local txt file , pass data profanity() function. do?
import urllib.request def read_file(): qoutes=open(r"c:\python34\profanity.txt") a=qoutes.read() profanity(a) qoutes.close() def profanity(b): connection = urllib.request.urlopen('http://www.wdylike.appspot.com/?q='+b) output = connection.read() print(output) connection.close() ##profanity() read_file()
the error log:
traceback (most recent call last): file "c:\python34\check_profanity.py", line 18, in <module> read_file() file "c:\python34\check_profanity.py", line 8, in read_file profanity(a) file "c:\python34\check_profanity.py", line 12, in profanity connection = urllib.request.urlopen('http://www.wdylike.appspot.com/?q='+b) file "c:\python34\lib\urllib\request.py", line 161, in urlopen return opener.open(url, data, timeout) file "c:\python34\lib\urllib\request.py", line 462, in open req = meth(req) file "c:\python34\lib\urllib\request.py", line 1106, in do_request_ raise urlerror('no host given') urllib.error.urlerror: <urlopen error no host given>
Comments
Post a Comment