From: Νίκος on 7 Aug 2010 15:37 On 7 ÎÏγ, 22:17, MRAB <pyt...(a)mrabarnett.plus.com> wrote: > ÎÎ¯ÎºÎ¿Ï wrote: > > On 7 ÎÏγ, 21:24, MRAB <pyt...(a)mrabarnett.plus.com> wrote: > > >> Use group capture: > > >>    found = re.match(r'<!-- (\d+) -->', 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 retrieve the string here? > > > and group? > > > Wehn a regex searched a .txt file when is retrieving something for it > > always retrieve it as string right? or can get it as a number as well? > > The 'r' prefix makes it a 'raw string literal'. That means that the > string literal won't treat backslashes as special. Before raw string > literals were added to the Python language I would have needed to write: > >    '<!-- (\\d+) -->' > > instead. > > (Actually, that's not strictly true in this case, because \d doesn't > have a special meaning Python strings, but it's a good idea to use raw > string literals habitually when writing regexes in order to reduce the > chance of forgetting them when they _are_ necessary. Well, that's what I > think, anyway. :-)) Couln't agree more! As the saying goes, better safe than sorry! :-)
From: Thomas Jollans on 7 Aug 2010 15:52 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'.
From: MRAB on 7 Aug 2010 16:07 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...
From: Νίκος on 7 Aug 2010 16:29 On 7 ÎÏγ, 22:52, Thomas Jollans <tho...(a)jollans.com> 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 the problem :-) Thanks alot Thomas and MRAB for ALL your help!
First
|
Prev
|
Pages: 1 2 3 Prev: Sequential Object Store Next: cscope like source code navigation for python code |