Python newbie, equal to a string?
Question: Trying to get my head arround why I cannot match the output of the IP against
a set IP and therefore render a outcome.

    
    
    import urllib
    import re
    
    ip = '212.125.222.196'
    
    url = "http://checkip.dyndns.org"
    
    print url
    
    request = urllib.urlopen(url).read()
    
    theIP = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request)
    
    print "your IP Address is: ",  theIP
    
    if theIP == '211.125.122.192':
        print "You are OK"
    else:
        print "BAAD"
    

The result is always "BAAD"


Answer: `re.findall` returns a list of matches, not a string. So you've two options
now, either iterate over the list and use `any`:

    
    
    theIP = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request)
    if any(ip == '211.125.122.192' for ip in theIP):
        print "You are OK"
    else:
        print "BAAD"  
    
    #or simply:
    
    if '211.125.122.192' in theIp:
        print "You are OK"
    else:
        print "BAAD"  
    

or use `re.search`:

    
    
    theIP = re.search(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request)
    if theIP and (theIP.group() == '211.125.122.192'):
        print "You are OK"
    else:
        print "BAAD"  
    

