On Wed, 16 Jul 2014 03:27:23 +0100, MRAB <pyt...@mrabarnett.plus.com> wrote: > Here's another use-case. > > Using the 're' module: > > >>> import re > >>> # Make a regex. > ... p = re.compile(r'(?P<first>\w+)\s+(?P<second>\w+)') > >>> > >>> # What are the named groups? > ... p.groupindex > {'first': 1, 'second': 2} > >>> > >>> # Perform a match. > ... m = p.match('FIRST SECOND') > >>> m.groupdict() > {'first': 'FIRST', 'second': 'SECOND'} > >>> > >>> # Try modifying the pattern object. > ... p.groupindex['JUNK'] = 'foobar' > >>> > >>> # What are the named groups now? > ... p.groupindex > {'first': 1, 'second': 2, 'JUNK': 'foobar'} > >>> > >>> # And the match object? > ... m.groupdict() > Traceback (most recent call last): > File "<stdin>", line 2, in <module> > IndexError: no such group > > It can't find a named group called 'JUNK'.
IMO, preventing someone from shooting themselves in the foot by modifying something they shouldn't modify according to the API is not a Python use case ("consenting adults"). > And with a bit more tinkering it's possible to crash Python. (I'll > leave that as an exercise for the reader! :-)) Preventing a Python program from being able to crash the interpreter, that's a use case :) --David _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com