I'm trying to update json dynamically by set of "rule" keymap.
basically it's working for different fields but not for this specific case, the sequence_handler function - get as the required sequence by name and increment the global variable .
This updating the json as expected:
CUSTOMER_NO = 1000
SUBSCRIBER_NO = 9000
def sequence_hanlder(sequence_name):
globals()[sequence_name] += 1
return globals()[sequence_name]
my_json = { "subscriber_no": "val1", "customer_no": "val2"}
key_map = {"subscriber_no": sequence_hanlder("SUBSCRIBER_NO"),
"customer_no": sequence_hanlder("CUSTOMER_NO")
}
#this works
my_json['subscriber_no'] = sequence_hanlde("SUBSCRIBER_NO")
I'd like to key the update values by
key_map(<filed_name>)())
but it leads to error:
my_json['subscriber_no'] = key_map['subscriber_no']()
...
TypeError: 'int' object is not callable