[issue25457] json dump fails for mixed-type keys when sort_keys is specified
naught101 added the comment: I want to do something like this: hashlib.md5(json.dumps(d, sort_keys=True)) So I can check if a dict's contents are the same as a DB version, but I can't guarantee that all the keys are strings, so it breaks, annoyingly. I would very much like the apply-default-function-then-sort approach. Until then, my work-around is this: def deep_stringize_dict_keys(item): """Converts all keys to strings in a nested dictionary""" if isinstance(item, dict): return {str(k): deep_stringize_dict_keys(v) for k, v in item.items()} if isinstance(item, list): # This will check only ONE layer deep for nested dictionaries inside lists. # If you need deeper than that, you're probably doing something stupid. if any(isinstance(v, dict) for v in item): return [deep_stringize_dict_keys(v) if isinstance(v, dict) else v for v in item] # I don't care about tuples, since they don't exist in JSON return item Maybe it can be of some use for others. -- nosy: +naught101 ___ Python tracker <https://bugs.python.org/issue25457> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27873] multiprocessing.pool.Pool.map should take more than one iterable
naught101 added the comment: It would be helpful if the docs at https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.map and in `help(Pool.map)` mentioned starmap in a "see also" section at the bottom. -- nosy: +naught101 ___ Python tracker <http://bugs.python.org/issue27873> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27873] multiprocessing.pool.Pool.map should take more than one iterable
naught101 added the comment: Happy to. What is the process? hg clone cpython, and make a patch from that and post it here? Or is there some pull-request style process available? -- ___ Python tracker <http://bugs.python.org/issue27873> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27873] multiprocessing.pool.Pool.map should take more than one iterable
naught101 added the comment: OK, one question, is Pool.map preferable to Pool.starmap in any particular cases? -- ___ Python tracker <http://bugs.python.org/issue27873> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27873] multiprocessing.pool.Pool.map should take more than one iterable
naught101 added the comment: Here you go. -- keywords: +patch Added file: http://bugs.python.org/file44851/mp.map.starmap.patch ___ Python tracker <http://bugs.python.org/issue27873> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com