Message313796
IDLE just added similar functionality to pyparse (issue 32940) using:
class ParseMap(dict):
def __missing__(self, key):
return 120 # ord('x')
# Map all ascii to 120 to avoid __missing__ call, then replace some.
trans = ParseMap.fromkeys(range(128), 120)
trans.update((ord(c), ord('(')) for c in "({[") # open brackets => '(';
trans.update((ord(c), ord(')')) for c in ")}]") # close brackets => ')'.
trans.update((ord(c), ord(c)) for c in "\"'\\\n#") # Keep these.
code = code.translate(trans)
Of course, all that is probably too much for a docs example, but it uses a mapping without the side effect of defaultdict. I wonder if defining the dict subclass with __missing__ and then the example of keeping only lowercase letters would work for the docs? |
|
Date |
User |
Action |
Args |
2018-03-13 23:47:12 | cheryl.sabella | set | recipients:
+ cheryl.sabella, rhettinger, Chris.Barker, docs@python, Jim.Jewett, serhiy.storchaka, ChrisBarker, Gaurav Tatke |
2018-03-13 23:47:12 | cheryl.sabella | set | messageid: <1520984832.08.0.467229070634.issue28612@psf.upfronthosting.co.za> |
2018-03-13 23:47:12 | cheryl.sabella | link | issue28612 messages |
2018-03-13 23:47:11 | cheryl.sabella | create | |
|