Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:52, Thomas Jollans wrote: > On 08/07/2010 09:36 PM, Νίκος wrote: > > > cookie.has_key('visitor') != 'nikos' > > This is always True. has_key returns a bool, which is never equal to any > string, even 'nikos'. if cookie.has_key('visitor') or re.search('cyta', host) is None: adresses

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Thomas Jollans wrote: On 08/07/2010 09:36 PM, Νίκος wrote: cookie.has_key('visitor') != 'nikos' This is always True. has_key returns a bool, which is never equal to any string, even 'nikos'. I missed that bit! :-) Anyway, the OP said "the 'stuff' never gets executed". Kinda puzzling... -- h

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Thomas Jollans
On 08/07/2010 09:36 PM, Νίκος wrote: > cookie.has_key('visitor') != 'nikos' This is always True. has_key returns a bool, which is never equal to any string, even 'nikos'. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:17, MRAB wrote: > Νίκος wrote: > > On 7 Αύγ, 21:24, MRAB wrote: > > >> Use group capture: > > >>      found = re.match(r'', firstline).group(1) > >>      print(page_id) > > > Worked like a charm! Thanks a lot! > > > So match method here not only searched for the string representation

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:07, MRAB wrote: > 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. The code block inside the if structure must be executes ONLY if the 'visitor' cookie is

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: On 7 Αύγ, 21:24, MRAB wrote: Use group capture: found = re.match(r'', firstline).group(1) print(page_id) Worked like a charm! Thanks a lot! So match method here not only searched for the string representation of the number but also convert it to integer as well? r s

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: On 7 Αύγ, 21:27, MRAB 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 get

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Thomas Jollans
On 08/07/2010 08:51 PM, Νίκος wrote: > On 7 Αύγ, 21:24, MRAB wrote: > >> Use group capture: >> >> found = re.match(r'', firstline).group(1) >> print(page_id) > > Worked like a charm! Thanks a lot! > > So match method here not only searched for the string representation > of the number

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 21:24, MRAB wrote: > Use group capture: > >      found = re.match(r'', firstline).group(1) >      print(page_id) Worked like a charm! Thanks a lot! So match method here not only searched for the string representation of the number but also convert it to integer as well? r stand for r

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 21:27, MRAB 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

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος 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 ant them to be as lon

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: Hello guys! Need your precious help again! In every html file i have in the very first line a page_id fro counetr countign purpsoes like in a format of a comment like this: and so on. every html file has its one page_id How can i grab that string representaion of a number from

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
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 ant them to be as long as i dont hav

How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
Hello guys! Need your precious help again! In every html file i have in the very first line a page_id fro counetr countign purpsoes like in a format of a comment like this: and so on. every html file has its one page_id How can i grab that string representaion of a number from inside the .ht