Hi I have a Python nested dictionaries like this:
fv_solution = {
'relaxationFactors':
{
'fields':
{
'\"(p|pa)\"': 0.3,
'alpha': 0.1,
},
'equations':
{
'\"(U|Ua)\"': 0.7,
'\"(k|epsilon)\"': 0.7,
}
},
'relaxationFactors2':
{
'fields':
{
'\"(p|pa)\"': 0.3,
'alpha': 0.1,
},
'equations':
{
'\"(U|Ua)\"': 0.7,
'\"(k|epsilon)\"': 0.7,
}
}
}
And I want to render to file like this:
relaxationFactors
{
fields
{
"(p|pa)" 0.3;
alpha 0.1;
}
equations
{
"(U|Ua)" 0.7;
"(k|epsilon)" 0.7;
}
}
relaxationFactors2
{
fields
{
"(p|pa)" 0.3;
alpha 0.1;
}
equations
{
"(U|Ua)" 0.7;
"(k|epsilon)" 0.7;
}
}
My best approach was using the replace filter but besides that its not a elegant solution the result is not as desired
my filter
{{ data|replace(':',' ')|replace('{','\n{\n')|replace('}','\n}\n')|replace(',',';\n')|replace('\'','') }}
result
{ # <- not needed
relaxationFactors2
{
fields
{
alpha 0.1;
"(p|pa)" 0.3 # <- missing ;
}
; # <- aditional ;
equations
{
"(U|Ua)" 0.7;
"(k|epsilon)" 0.7 # <- missing ;
}
} # <- not needed
; # <- aditional ;
relaxationFactors
{
fields
{
alpha 0.1;
"(p|pa)" 0.3 # <- missing ;
}
; # <- aditional ;
equations
{
"(U|Ua)" 0.7;
"(k|epsilon)" 0.7 # <- missing ;
}
}
} # <- not needed ;