I'm working on a script that requires manipulation of locals()
, and I'm having trouble removing values from it. I've tried locals().pop(key)
and del locals()[key]
, but neither works.
As an example:
def locals_test():
a, b = 1, 2
locals().pop('a')
del locals()['b']
return locals()
def dict_test():
test = {'a':1, 'b':2}
test.pop('a')
del test['b']
return test
print(locals_test()) # --> {'a':1, 'b':2}
print(dict_test()) # --> {}
I'm trying to replicate the behavior of dict_test()
in locals_test()
, but I've yet to find a solution. Does anyone know how to solve this?