How to grab a number from inside a .html file using regex
MRAB
python at mrabarnett.plus.com
Sat Aug 7 15:07:49 EDT 2010
Νίκος wrote:
> On 7 Αύγ, 21:27, MRAB <pyt... at mrabarnett.plus.com> wrote:
>> Νίκος wrote:
>>> i also dont know what wrong with this line:
>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>> hostmatch = re.search('cyta', host)
>>> if cookie.has_key('visitor') != 'nikos' or hostmatch is None:
>>> # do stuff
>>> the 'stuff' never gets executed, while i want them to be as long as i
>>> dont have regex match!
>> Try printing out repr(host). Does it contain "cyta"?
>
> Yes it does contain it as print shown!
>
> is something wrong with this line in logic or syntax?
>
> if cookie.has_key('visitor') != 'nikos' or re.search('cyta', host) is
> None:
> # do database stuff
>
You said "i want them to be as long as i dont have regex match".
re.search('cyta', host) will return None if there's no match, but you
said "Yes it does contain it", so there _is_ a match, therefore:
hostmatch is None
is False.
More information about the Python-list
mailing list