Please see the string below. I am using lmfit
to do some fitting and then using yaml
to save the results to a dictionary. I am getting the following string generated by the lmfit result:
"[[Fit Statistics]]\n # fitting method = leastsq\n # function\
\ evals = 4\n # data points = 70\n # variables = 2\n chi-square\
\ = 5.5122e+09\n reduced chi-square = 81062428.0\n Akaike info crit\
\ = 1276.72198\n Bayesian info crit = 1281.21897\n[[Variables]]\n Amplitude:\
\ 12.6121224 +/- 0.24761617 (1.96%) (init = 12.61212)\n Radius: \
\ 41.0677874 +/- 0.11681467 (0.28%) (init = 41.06779)\n Polydispersity:\
\ 0.05 (fixed)\n Background: 1e-05 (fixed)\n Roughness: 0 (fixed)\n\
[[Correlations]] (unreported correlations are < 0.100)\n C(Amplitude, Radius)\
\ = -0.446"
What would be the best way to present it beautifully. (For eg: \n
doesn't seem to work)
If you just want to "present" this aesthetically for your own observations, try this:
ls=string.split("\n") print(ls)
If you want to actually parse it or use it for other purposes from string than look at converting the list produced to tuples or dictionary. This is how you can do it:
`def Convert(tup, di):
for a, b in tup:
di.setdefault(a, []).append(b)
return di`
`ls=string.split("\n")
ls2=[]
d={}
for x in ls:
if '=' in x:
(a,b) = x.split("=")
ls2.append((a,b))
elif ':' in x:
(a,b) = x.split(":")
ls2.append((a,b))
(Convert(ls2, d)) `