[Solved] write() file by inserting dict in specific key order and format


Probably the closest short of looping and building a string, is something using pprint.pformat, such as:

>>> from pprint import pformat
>>> my_dct = dict(
    k1=1,
    k3=3,
    k2=2,)
>>> print('my_dct = {{\n {}\n}}'.format(pformat(my_dct, width=1)[1:-1]))
my_dct = {
 'k1': 1,
 'k2': 2,
 'k3': 3
}

solved write() file by inserting dict in specific key order and format