字符串串联-TypeError:一元运算符的错误操作数类型:'str'

问题描述

我正在尝试将一些拟合算法的输出写入文本日志文件

with open(outputPath + 'fit_logfile.txt',mode='a') as fit_logfile:
    fit_logfile.write('\n'
                        + inputPath + filename + ':\n'
                        + 'Initial parameters:\n',+ 'x0_init = ' + str(params_init[0]) + '\n'
                        + 'y0_init = ' + str(params_init[1]) + '\n'
                        + 'Imax_init = ' + str(params_init[2]) + '\n'
                        + 'FHWM_init = ' + str(params_init[3]) + '\n'
                        + 'Optimized parameters:\n'
                        + 'x0_opt = ' + str(params_opt[0]) + '\n'
                        + 'y0_opt = ' + str(params_opt[1]) + '\n'
                        + 'Imax_opt = ' + str(params_opt[2]) + '\n'
                        + 'FHWM_opt = ' + str(params_opt[3]) + '\n'
                        + 'Standard deviations:\n'
                        + 'sigma_x0 = ' + str(params_err[0]) + '\n'
                        + 'sigma_y0 = ' + str(params_err[1]) + '\n'
                        + 'sigma_Imax = ' + str(params_err[2]) + '\n'
                        + 'sigma_FWHM = ' + str(params_err[3]) + '\n')

但是,我遇到此错误

TypeError                                 Traceback (most recent call last)
<ipython-input-11-9d3a854ada12> in <module>()
     54                             + 'sigma_y0 = ' + str(params_opt[1]) + '\n'
     55                             + 'sigma_Imax = ' + str(params_opt[2]) + '\n'
---> 56                             + 'sigma_FWHM = ' + str(params_opt[3]) + '\n')
     57
     58

TypeError: bad operand type for unary +: 'str'

我想念什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)