Is there a way where I’m able to generate the code in a file for a python data structure.
For example, if I had a dictionary, it would create a file with:
name_of_variable = { key: value, key:value}
and so on. The use for this is testing where I don’t want to manually code up a lot of data structures for my tests and I’d rather create some template structures where I can edit manually.
Thanks in advance.
For simple data structures such
dict,list,setand other built-in things you can userepr():Documentation says: ”For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to
eval()”.