Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48849

how can I check if group member exist ?

Newsgroups comp.lang.python
Date 2013-06-21 02:07 -0700
Message-ID <caa3e87c-922e-49e2-ae16-7502b1b365d3@googlegroups.com> (permalink)
Subject how can I check if group member exist ?
From Hans <hansyin@gmail.com>

Show all headers | View raw


Hi,

I'm doing a regular expression matching, let's say "a=re.search(re_str,match_str)", if matching, I don't know how many str/item will be extracted from re_str, maybe a.group(1), a.group(2) exist but a.group(3) does not. 

Can I somehow check it? something like:
if exist(a.group(1)): print a.group(1)
if exist(a.group(2)): print a.group(2)
if exist(a.group(3)): print a.group(3)


I don't want to be hit by "Indexerror":
>>>print a.group(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: no such group
>>> 

thanks!!!

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

how can I check if group member exist ? Hans <hansyin@gmail.com> - 2013-06-21 02:07 -0700
  Re: how can I check if group member exist ? Peter Otten <__peter__@web.de> - 2013-06-21 11:25 +0200
  Re: how can I check if group member exist ? Ben Finney <ben+python@benfinney.id.au> - 2013-06-21 19:49 +1000

csiph-web