python-benedict/benedict/core/move.py

12 lines
336 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
def move(d, key_src, key_dest, overwrite=True):
if key_dest == key_src:
return
if key_dest in d and not overwrite:
2020-09-07 17:25:34 +00:00
raise KeyError(
2020-09-10 17:06:43 +00:00
'Invalid key: "{}", key already in target dict '
'and `overwrite` is disabled.'.format(key_dest))
d[key_dest] = d.pop(key_src)