You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For non-repeated groups, one can use match.groupdict() to retrieve a dictionary of ALL groups and their values, including un-matched groups. But there is no equivalent for repeated groups: match.captures() only returns values for groups given explicitly in arguments, while groupdict() doesn't include multiple values.
I suggest either:
Change API of captures() so that captures() (no args) returns a dictionary of ALL groups, not just group 0 - this would be the most convenient and intuitive, but would break existing code if somebody relies on this feature.
Add a boolean argument to captures(), say "all", equal False by default, to let the client indicate that a full dictionary is expected.
Add new method, say capturesdict() to return dict of all groups.
Thanks
Marcin
What version of the product are you using? On what operating system?
0.1.20130120
Linux, Python 2.7.2
The text was updated successfully, but these errors were encountered:
Original comment by Marcin Wojnarski (Bitbucket: mwojnars, GitHub: mwojnars).
Yes, it should behave in this way.
Usecase: web scraping, extraction of many different values from a complex html page in one go (for example, profile page of a product, with different properties listed in a fixed layout) - after applying a regex the next step is to take *all* extracted data as a dict, not one by one.
Original report by Marcin Wojnarski (Bitbucket: mwojnars, GitHub: mwojnars).
Hi,
For non-repeated groups, one can use match.groupdict() to retrieve a dictionary of ALL groups and their values, including un-matched groups. But there is no equivalent for repeated groups: match.captures() only returns values for groups given explicitly in arguments, while groupdict() doesn't include multiple values.
I suggest either:
Change API of captures() so that captures() (no args) returns a dictionary of ALL groups, not just group 0 - this would be the most convenient and intuitive, but would break existing code if somebody relies on this feature.
Add a boolean argument to captures(), say "all", equal False by default, to let the client indicate that a full dictionary is expected.
Add new method, say capturesdict() to return dict of all groups.
Thanks
Marcin
What version of the product are you using? On what operating system?
0.1.20130120
Linux, Python 2.7.2
The text was updated successfully, but these errors were encountered: