-1

I would like to collect different type of datas into a file. Here is a part of the code.

val = str(float(data[-1]))
val_dB = float(val)
val_dB = math.log(val_dB, 10) * 10
myfile = open('../../../MLI_values/mli_value.txt', 'a')
myfile.write(date_ID + " " + val + val_dB + "\n")
myfile.close()

But it gives back an error:

myfile.write(date_ID + " " + val + val_dB + "\n")
TypeError: cannot concatenate 'str' and 'float' objects

How can I solve it to put them together? (into columns) into a file?

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Krsztr
  • 101
  • 2
  • 3
    Possible duplicate of [Cannot concatenate 'str' and 'float' objects?](https://stackoverflow.com/questions/16948256/cannot-concatenate-str-and-float-objects) – Georgy Nov 07 '18 at 09:05

1 Answers1

0

Change:

myfile.write(date_ID + " " + val + val_dB + "\n")

to:

myfile.write(date_ID + " " + val + " " + str(val_dB) + "\n")
Paul R
  • 208,748
  • 37
  • 389
  • 560