Python Forum

Full Version: Listing groups
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Suppose I see a line of code like
elif m.group('status').lower() in ['stopped', 'failed']:
And I want to see all statuses that are available.
I tried
logging.warning('m.groups = ' + ' '.join(str(m.group)))
But I get
Output:
TypeError: type object argument after * must be an iterable, not builtin_function_or_method
I have tried several methods, but I always get either the error message above or
Output:
m.groups = < b u i l t - i n m e t h o d g r o u p o f r e . M a t c h o b j e c t a t 0 x 7 f b 2 7 0 a 4 7 1 8 8 >
which is not what I'm looking for.

Is there a way of printing out all of the groups in the above scenario?

I now think that it is not possible, because groups is a method that searches for a regex, rather than being a list.
Are you using regular expressions here? Please take a moment to re-read your post and consider what context you should be providing that currently isn't here.
You're joining the representation of a method, because you're not calling it.
Instead of calling group(number), you should call groups() on the match.
This will return the results of all groups in a tuple.