[Python-Dev] Another case for frozendict (original) (raw)
R. David Murray rdmurray at bitdance.com
Wed Jul 16 15:37:55 CEST 2014
- Previous message: [Python-Dev] Another case for frozendict
- Next message: [Python-Dev] Another case for frozendict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 16 Jul 2014 03:27:23 +0100, MRAB <python at mrabarnett.plus.com> wrote:
Here's another use-case.
Using the 're' module: >>> import re >>> # Make a regex. ... p = re.compile(r'(?P\w+)\s+(?P\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 "", line 2, in 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
- Previous message: [Python-Dev] Another case for frozendict
- Next message: [Python-Dev] Another case for frozendict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]