I am reading configuration data from a YAML file and using that info as a Python dictionary. When I change the value of the keys, the code sorts the keys in the file alphabetically. I want to avoid sorting. Below is the screenshot of how the file looks before and after it gets sorted following the I/O operation.
And here's the code I am using to perform the operation.
def change_last_record_id(record_id, table_ref):
"""
Used for changing the value of 'last_record_id' in the 'config.yaml' file
:param rcord_id: record_id: Value that needs to be changed.
:param record_id: table_ref: Key which contains the value
:return: None
"""
data_dictionary = yaml.load(open("config.yaml"), Loader=yaml.FullLoader)
data_dictionary["last-id-"+table_ref] = record_id
with open("config.yaml", "w") as f:
yaml.dump(data_dictionary, f)