Preserving quotes in numeric keys when writing dictionary to yaml

Viewed 15

I have yaml files for which some keys have the form 'n_n' for integer n. Example:

'1_0':
>    age: 23
>
>    eyes: blue

These are read in fine as python dictionaries, but when written to yaml the "numeric" keys lose their single-quotes and become

1_0:
>  age: 23
>
>  eyes: blue

And (naturally) on subsequent read/write they become

10:

>    age: 23
> 
>    eyes: blue

I don't want to force every key to be quoted ('age', 'eyes', 'etc'). Is there a solution?

0 Answers
Related