Hey guys,
I have some code:
import urllib2 as url
import subprocess
import os
webs=open("url.txt",'r')
read_webs=webs.read()
def get_html():
try:
req=url.urlopen(read_webs)
res=req.read()
return True
except:
print("<Error reading from the website>")
def get_command():
if True:
for x in res:
if(x!='<'):
command+=x
else:
break
determine()
command=""
def determine():
format=command[len(command)-3:]
print format
get_html()
get_command()
The problem is:
>>>
Traceback (most recent call last):
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\Accepshun.py", line 32, in <module>
get_command()
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\Accepshun.py", line 18, in get_command
for x in res:
NameError: global name 'res' is not defined
>>>
I understand that get_command() doesn't know what 'res' is, but how do I solve this problem?