text: Q:
  
  Checking condition while Exception handling in python
  
  This is part of my code in python. I want to check the error message and if HTTPError() then I want to add the host to the file ok.txt. But it doesn't work. what is the problem here?
  except urllib2.URLError, e:
          print '%-15s\t%15r' % (url.strip(), e)
          if e == 'HTTPError()':
              OK.write('%-15s' % (url.strip()) + '\n')
              OK.flush()
  
  When I run whole script the output is something like this:
  http://a.com        HTTPError()
  http://b.com    URLError(timeout('timed out',),)
  http://c.com    URLError(timeout('timed out',),)
  http://d.com    URLError(error(111, 'Connection refused'),)
  http://e.com           200
  
  A:
  
  Use isinstance() to check whether or not your error is of type HTTPError:
  except urllib2.URLError as e: # use the "as e" instead of the old style comma delimitation.
      print '%-15s\t%15r' % (url.strip(), e)
      if isinstance(e, HTTPError):
          OK.write('%-15s' % (url.strip()) + '\n')
          OK.flush()
  
  