On Fri, Dec 6, 2019, at 14:50, MRAB wrote: > On 2019-12-06 18:24, Andrew Barnert via Python-ideas wrote: > > On Dec 6, 2019, at 09:51, Random832 <random...@fastmail.com> wrote: > >> > >> If match objects are too hard to use, maybe they should be made more > >> user-friendly? What about adding str and iterable semantics to match > >> objects so it can be used as str(re.search(...)); tuple(re.search(...)); > >> a, b = re.search(...)? > > > > That’s a clever idea, and it might work. > > > 1. Match objects are also be returned by re.match, and you wouldn't > expect that to look for more matches.
I'm not sure what you meant by looking for more matches, though I suspect it's because, as below, I wasn't clear with what I meant by iterable semantics. > 2. What would tuple(re.search(...)) do? Wouldn't it do the same as > tuple(re.findall(...))? I intended the tuple [well, the iterable semantics that would allow the tuple call to succeed] to return m.groups(), i.e. the same tuple as re.findall()[0] does when the re contains capturing groups. Sorry for not making that clear enough. > 3. a, b = re.search(...) would fail if it didn't return exactly 2 > matches 2 capturing groups, not 2 matches. Again, sorry for not making that explicitly clear. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ESULRR2Z7NWAMZ7ZI2KNCFHZFHWIRUCW/ Code of Conduct: http://python.org/psf/codeofconduct/